MVC : The parameters dictionary contains a null entry for parameter 'k' of non-nullable type 'System.Int32'

后端 未结 5 803
情书的邮戳
情书的邮戳 2020-12-05 17:08

I am new to MVC. In My Application , I\'m Retrieving the Data from Mydatabase. but when I run my Application it show Error Like This this is my url

<         


        
5条回答
  •  清歌不尽
    2020-12-05 17:41

    It appears that you are using the default route which is defined as this:

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
    

    The key part of that route is the {id} piece. If you look at your action method, your parameter is k instead of id. You need to change your action method to this so that it matches the route parameter:

    // change int k to int id
    public ActionResult DetailsData(int id)
    

    If you wanted to leave your parameter as k, then you would change the URL to be:

    http://localhost:7317/Employee/DetailsData?k=4
    

    You also appear to have a problem with your connection string. In your web.config, you need to change your connection string to this (provided by haim770 in another answer that he deleted):

    
      
    
    

提交回复
热议问题