locked
Server Error! RRS feed

  • Question

  • User1421620300 posted

    Can i get help with the following error its been bothering me overnight! It has something to do with My user controller and i think maybe the Id parameters of my application, but i am not for sure. I have did a review and see no conflicts so i cannot identify error? Markus

    Links:

    https://ibb.co/DRqXWLr
    https://ibb.co/h1qLNnL
    https://ibb.co/Rbn5F2M

    Wednesday, May 20, 2020 1:50 PM

Answers

  • User-474980206 posted

    It’s pretty clear error. You are not passing the Id parameter to the index call. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 20, 2020 2:22 PM
  • User753101303 posted

    Hi,

    You are using https://localhost:44316/User/Index and so yoou don't have any parameter that could be used to populate the public JsonResult Index(int Id) parameter.

    What if you try https://localhost:44316/User/Index/1 the Id value will be populated with 1.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 20, 2020 6:07 PM
  • User753101303 posted

    Unclear. I don't see exactly https://localhost:44316/User/Index/1 (seems you always tried with an extra / at least)

    Of course I have no idea which value is valid. By "doesn't work" to you mean it fails with the same error or wiht some other error know? Please be always explicit about which error you have.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 20, 2020 7:39 PM
  • User475983607 posted

    I followed the following suggestions!

    You defined the MVC Index Action to always expect an id route parameter but the client application is not sending the route value.    The follow example code reproduces the error message in your first post. 

    The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(Int32)' in 'MvcDemo.Controllers.UserController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
    Parameter name: parameters 

        public class UserController : Controller
        {
            // GET: User
            public ActionResult Index()
            {
                return View();
            }
    
            public ActionResult AddUser(int id)
            {
                ViewBag.Id = id;
                return View();
            }
        }

    Index

    @{
        ViewBag.Title = "Index";
    }
    
    <h2>Index</h2>
    
    <div>
        <a href="/user/adduser/1">Good Link</a>  
    </div>
    <div>
        <a href="/user/adduser/">Exception</a>
    </div>

    AddUser

    @{
        ViewBag.Title = "AddUser";
    }
    
    <h2>AddUser</h2>
    
    <div>
        @ViewBag.Id
    </div>

    Routing is a predominate feature in MVC.   Take time to learn the fundamentals.

    https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/controllers-and-routing/asp-net-mvc-routing-overview-cs

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 20, 2020 8:26 PM
  • User1686398519 posted

    Hi,  Markus33

    I checked the link you gave and found that there is no Index page under your "User" folder, so you will get an error when you visit the page.

    I suggest that you can create pages like this.

    Best Regards,

    YihuiSun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 21, 2020 2:47 AM

All replies

  • User-474980206 posted

    It’s pretty clear error. You are not passing the Id parameter to the index call. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 20, 2020 2:22 PM
  • User1421620300 posted

    Bruce, i can only understand that i have Index with Id requirement available. Whats is the apparent problem? Is their something wrong with my casing or is it the null reference  to the database?

    public class UserController : Controller
    {

    private Portfolio55DbContext db = null;

    //Portfolio55DbContext db = new Portfolio55DbContext();

    public UserController()
    {
    db = new Portfolio55DbContext();
    }
    // GET: User
    public JsonResult Index(int Id)
    {
    var users = db.Users.Find(Id);
    return Json(users, JsonRequestBehavior.AllowGet);
    }

    Wednesday, May 20, 2020 5:57 PM
  • User753101303 posted

    Hi,

    You are using https://localhost:44316/User/Index and so yoou don't have any parameter that could be used to populate the public JsonResult Index(int Id) parameter.

    What if you try https://localhost:44316/User/Index/1 the Id value will be populated with 1.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 20, 2020 6:07 PM
  • User1421620300 posted

    I followed the following suggestions! Markus

    https://localhost:44316/Home/Index/1/ doesnt work

    https://localhost:44316/#/    Suggestion from project owner. doesnt work.

    https://localhost:44316/Home/Index/1/#/  doesnt work.

    <h2>User</h2>
    <a href="#/adduser" class="btn btn-primary">Create New</a>  //Hash is added to URL.
    <div class="panel panel-default">
    <div class="panel-heading">
    List User

    Inspector errors:

    GET https://localhost:44316/User/Index 500    VM155:1 

    Possibly unhandled rejection: undefined    angular.js:15570

    Wednesday, May 20, 2020 7:27 PM
  • User753101303 posted

    Unclear. I don't see exactly https://localhost:44316/User/Index/1 (seems you always tried with an extra / at least)

    Of course I have no idea which value is valid. By "doesn't work" to you mean it fails with the same error or wiht some other error know? Please be always explicit about which error you have.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 20, 2020 7:39 PM
  • User475983607 posted

    I followed the following suggestions!

    You defined the MVC Index Action to always expect an id route parameter but the client application is not sending the route value.    The follow example code reproduces the error message in your first post. 

    The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(Int32)' in 'MvcDemo.Controllers.UserController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
    Parameter name: parameters 

        public class UserController : Controller
        {
            // GET: User
            public ActionResult Index()
            {
                return View();
            }
    
            public ActionResult AddUser(int id)
            {
                ViewBag.Id = id;
                return View();
            }
        }

    Index

    @{
        ViewBag.Title = "Index";
    }
    
    <h2>Index</h2>
    
    <div>
        <a href="/user/adduser/1">Good Link</a>  
    </div>
    <div>
        <a href="/user/adduser/">Exception</a>
    </div>

    AddUser

    @{
        ViewBag.Title = "AddUser";
    }
    
    <h2>AddUser</h2>
    
    <div>
        @ViewBag.Id
    </div>

    Routing is a predominate feature in MVC.   Take time to learn the fundamentals.

    https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/controllers-and-routing/asp-net-mvc-routing-overview-cs

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 20, 2020 8:26 PM
  • User1686398519 posted

    Hi,  Markus33

    I checked the link you gave and found that there is no Index page under your "User" folder, so you will get an error when you visit the page.

    I suggest that you can create pages like this.

    Best Regards,

    YihuiSun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 21, 2020 2:47 AM