Asp.net mvc ASP MVC3 ActionLink未呈现变量
我试图使用ASP MVC3操作链接导航到另一个视图(同一控制器)。该视图附着到将复合键用作主键的模型。下面是写在视图上的操作链接Asp.net mvc ASP MVC3 ActionLink未呈现变量,asp.net-mvc,asp.net-mvc-3,asp.net-mvc-2,actionlink,Asp.net Mvc,Asp.net Mvc 3,Asp.net Mvc 2,Actionlink,我试图使用ASP MVC3操作链接导航到另一个视图(同一控制器)。该视图附着到将复合键用作主键的模型。下面是写在视图上的操作链接 @Html.ActionLink("Edit Agent", "AgentEdit", "BankListMasterController", new { @agentId = int.Parse(item.AgentId), @id = item.ID}) 但是,当渲
@Html.ActionLink("Edit Agent", "AgentEdit", "BankListMasterController",
new { @agentId = int.Parse(item.AgentId), @id = item.ID})
但是,当渲染时,它将渲染为以下内容
http://localhost:2574/BankListMaster/AgentEdit?Length=24
这显然是一个错误:
The parameters dictionary contains a null entry for parameter 'agentId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ViewResult AgentEdit(Int32, Int32)' in 'Monet.Controllers.BankListMasterController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
以下是良好测量的控制器方法:
public ViewResult AgentEdit(int agentId, int id)
{
string compare = agentId.ToString();
BankListAgentId agent = (from c in db.BankListAgentId
where c.ID == id &&
c.AgentId.Equals(compare)
select c).Single();
return View("AgentEdit", agent);
}
这应该能奏效
理由是:根据
你找不到有(HtmlHelper,string,string,string,object)的方法,但是有(HtmlHelper,string,string,object,object),最后一个对象是路由值,最后一个是html属性。根据你提供的参数,调用了错误的ActionLink 问题是它正在“尝试序列化字符串对象” 以下是“链接中的‘长度’参数”问题的标准答案:
@Html.ActionLink("Edit Agent", "AgentEdit", "BankListMasterController",
new { agentId = int.Parse(item.AgentId), id = item.ID}, null)