-1

我需要创建一个隐藏变量,其结果为Url.Action. 以下代码不会产生所需的结果。需要纠正什么以产生所需的结果?

当前输出

<input name="/Controller/Action" type="hidden" value="{ Id = hiddenUrl }" />

所需输出

<input id="hiddenUrlName" type="hidden" value="/Controller/Action" />

代码

 <div class="loader">
    @Html.Hidden(@Url.Action("Action", "Controller"),new { Id = "hiddenUrl"})
 </div>
4

2 回答 2

4

You've got your overloads mixed up. You want this one http://msdn.microsoft.com/en-us/library/dd492181(v=vs.108).aspx

@Html.Hidden("hiddenUrlName", Url.Action("Action", "Controller"),
                                                         new { Id = "hiddenUrl"})

You also don't need the @ in the Url.Action

Or which is directly equivalent but not using the HTML helpers.

<input id="hiddenUrl" name="hiddenUrlName" type="hidden" 
                             value="@Url.Action("Action", "Controller")" />
于 2013-09-09T08:11:28.060 回答
0

也许试试这个:

@Html.Hidden("hiddenUrlName", Url.Action("Action", "Controller"))

输出应该是这样的:

<input id="hiddenUrlName" name="hiddenUrlName" type="hidden" value="/Controller/Action" />
于 2013-09-09T11:10:44.043 回答