读操作隐藏字段的值? [英] reading hidden field value in action?
问题描述
在MVC-4剃须刀认为我有2列的HTML表。第一列显示的字段,并把它存储为一个隐藏字段。表中的第2列有一个< A>
点击它重定向到其他一些控制和行动
IN MVC-4 Razor view I have a html table with 2 columns. 1st columns shows a field and also stores it as a hidden field. 2nd column of table has a <a>
clicking on it it redirect to some other control and action.
<tbody>
@foreach (var row in Model.Conversions)
{
<tr>
<td>@(Html.DisplayFor(m => row.LastUpdatedDate))
@(Html.Hidden("DateFrom",@row .LastUpdatedDate))
</td>
<td><a href="@Url.Action("ExchangeRateDetails", "ExchangeRate", new { currencyCode = @row.CurrencyCodeFromTo })">+</a>
</td>
</tr>
}
</tbody>
里面的动作,我想读的隐藏字段的值,但它为空。这是我的code:
Inside action I am trying to read hidden field value but it is null. Here is my code:
public virtual ActionResult ExchangeRateDetails(string currencyCode)
{
var dat = Request.Form["DateFrom"];
}
问题:
我发现隐藏字段值为空。我的期望是它应有的价值未来的形式隐藏字段。我无法通过这个值作为查询字符串。能否请你指导和帮助我怎样才能在行动中读取隐藏字段的值?
I am finding hidden field value as null. My expectation is it should have value coming form hidden field. I cant pass this value as a query string. Can you please guide and help me how I can read hidden field values in action ?
许多感谢您的指导和帮助我。
Much thanks for your guidance and helping me.
感谢
推荐答案
使用的FormCollection
Use FormCollection
[HttpPost]
public virtual ActionResult ExchangeRateDetails(FormCollection collection,string currencyCode)
{
string value = Convert.ToString(collection["DateFrom"]);
...
return View();
}
和你为什么使用@(当时hidenfield?请改变,像,删除()中的前html.hidden
and Why you used @( then hidenfield ? please change that like , remove '()' in before html.hidden
@Html.Hidden("DateFrom",@row .LastUpdatedDate)
修改
和添加的的形式=邮报的在你的锚标记
And Add form="Post" in your anchor tag
喜欢
<a href="@Url.Action("ExchangeRateDetails", "ExchangeRate", new { currencyCode = @row.CurrencyCodeFromTo **,form="post"**})">+</a>
它的工作对我来说。如果您通过上面的编辑code。在你的锚标记添加的形式=邮报,然后你不需要任何其他的变化,你的code一直在努力与这个小变化
It's working to me . If you add form="Post" in your anchor tag by the above edited code , Then you don't need any other changes ,Your code always working with on this small change .
这篇关于读操作隐藏字段的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!