ASP.NET MVC3:带有隐藏字段的模型绑定
这是视图
@using (Html.BeginForm("Deleted", "Location"))
{
Html.Hidden("LocationID", Model.LocationID );
<input type = "submit" value = "Delete" />
}
这是应该接收数据的方法。
public ActionResult Deleted(int LocationID)
{
//Do something with LocationID
return View();
}
当我运行代码时,LocationID 始终为 null。我错过了什么吗?
感谢您的帮助
Here's the view
@using (Html.BeginForm("Deleted", "Location"))
{
Html.Hidden("LocationID", Model.LocationID );
<input type = "submit" value = "Delete" />
}
And here's the method that's supposed to receive the data.
public ActionResult Deleted(int LocationID)
{
//Do something with LocationID
return View();
}
When I run the code, LocationID is always null. Am I missing something?
Thanks for helping
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用
Html.Hidden
返回包含隐藏字段的IHtmlString
。但是,您没有对返回的字符串执行任何操作。
您需要使用
@
将字符串呈现到页面。Calling
Html.Hidden
returns anIHtmlString
containing a hidden field.However, you aren't doing anything with the returned string.
You need to render the string to the page using an
@
.