参数字典包含方法'system.web.mvc.actionresult languageedit(int32)的非可空类型'system.int32'的参数'id'的空条目 [英] The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'system.int32' for method 'system.web.mvc.actionresult languageedit(int32)

查看:70
本文介绍了参数字典包含方法'system.web.mvc.actionresult languageedit(int32)的非可空类型'system.int32'的参数'id'的空条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在控制器中有一个操作方法 CountryController.cs

I have a action method in the controller CountryController.cs

public ActionResult LanguageEdit(int id)
       {



另外要导航到它,


Also to navigate to it,

@Html.ActionLink("Edit", "LanguageEdit", "Country", new { id = item.LanguageId }





我检查了价值



I checked the value

item.LanguageId



它是4.但是我收到了例外:


It is 4. But I received the exception:

The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult LanguageEdit(Int32)





为什么?



我的尝试:



我的路线配置是:



Why?

What I have tried:

My route's configuration is:

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

推荐答案

你可能会想试试

You might want to try
@Html.ActionLink("Edit", "LanguageEdit", "Country", new { id = item.LanguageId }, null)

而不是

如果你检查 ActionLink重载列表你会看到没有断言链接文本,动作名称,控制器名称和路由值dictionary.But有一个接受那些params和html属性字典

instead
If you check List of ActionLink overloads you'll see that there is none wich assepts link text, action name, controller name and route values dictionary.But there is one which accepts those params and html attributes dictionary


这篇关于参数字典包含方法'system.web.mvc.actionresult languageedit(int32)的非可空类型'system.int32'的参数'id'的空条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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