参数词典共包含非可空类型的参数'ID'System.Int32的空项 [英] The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32'

查看:1549
本文介绍了参数词典共包含非可空类型的参数'ID'System.Int32的空项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立我的第一个MVC应用程序,我有一个表包含3列数据库:


  1. 标识 - >主键

  2. 用户名

  3. 密码

当我点击编辑链接编辑的记录,它的投掷以下情况除外:


  

参数词典共包含参数非可空类型'System.Int32'的'身份证'的方法'System.Web.Mvc.ActionResult编辑(Int32)已'在'MvcApplication1.Controllers.UserController的空项。一个可选参数必须是引用类型,可空类型,或声明为可选参数。
  参数名:参数


下面是我的编辑code:

 公众的ActionResult编辑(INT ID,用户集合)
{
    UserDBMLDataContext DB =新UserDBMLDataContext();
    变种Q =从db.User_Login_Details ABC
            其中,abc.Id == ID
            选择ABC;    IList的LST = q.ToList();    User_Login_Details userLook =(User_Login_Details)LST [0];    userLook.Username = collection.UserName;
    userLook.Password = collection.Password;
    db.SubmitChanges();
    返回RedirectToAction(「指数」);
}


解决方案

您期望的 ID 参数在您的网址,但你没有提供的。如:

  http://yoursite.com/controller/edit/12
                                    缺少^^

I am building My first MVC application, I have a table in database containing 3 columns:

  1. Id --> primary key
  2. Username
  3. password

When I am clicking on edit link edit a record, its throwing following exception:

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

Here is my edit code:

public ActionResult Edit(int id, User collection)
{
    UserDBMLDataContext db = new UserDBMLDataContext();
    var q = from abc in db.User_Login_Details
            where abc.Id == id
            select abc;

    IList lst = q.ToList();

    User_Login_Details userLook = (User_Login_Details)lst[0];

    userLook.Username = collection.UserName;
    userLook.Password = collection.Password;
    db.SubmitChanges();
    return RedirectToAction("Index");                  
}

解决方案

You are expecting an id parameter in your URL but you aren't supplying one. Such as:

http://yoursite.com/controller/edit/12
                                    ^^ missing

这篇关于参数词典共包含非可空类型的参数'ID'System.Int32的空项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆