Html.Hidden返回不同的值

时间:2011-08-26 09:26:34

标签: asp.net-mvc-2

我有问题,我无法理解。

int i = Convert.ToInt32(Model.dt);
MvcHtmlString s = Html.Hidden("DishType", Convert.ToInt32(Model.dt));
MvcHtmlString ss = Html.Hidden("DishType", 4);

i = 4

s =输入id =“DishType”name =“DishType”type =“hidden”value =“22”

ss = input id =“DishType”name =“DishType”type =“hidden”value =“22”

为什么值为22,如果在两种情况下参数都是4 ???

1 个答案:

答案 0 :(得分:0)

这是因为你传入了错误的位置

您需要使用的是:

<%= Html.Hidden(“name”,null,new {Value =“your attributes here”})%>

另请阅读此处: http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k%28SYSTEM.WEB.MVC.HTML.INPUTEXTENSIONS.HIDDEN%29;k%28TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22%29;k%28DevLang-CSHARP%29&rd=true