0

如何将文本框值传递给 @html.hidden() 以转到我的控制器 MVC,我的视图是:

@using (Html.BeginForm("Reject", "Maker", FormMethod.Get))
{
 <div class="filed">
 <form class="RejectForm">
  <p> <input type="text" class="RejectTextBox" name="HidField" id="HidField" value="" placeholder="سبب الرفض"> 
  @Html.ValidationMessage("_strRejectReason", new { @style = "color:red" })</p>
  <br />

  <input id="RejectButton" type="submit" value="Reject"/>                                           
  </form>
  </div>

 @Html.HiddenFor(model => model._strRejectReason, new { id = "HidField"})
 @Html.Hidden("id", item.Id);
 <p>@Html.ValidationMessage("CustomError", new { @style = "color:red" })</p>
 }

问题是我的控制器接收到模型的一个空对象,该模型包含两个属性 int id ,字符串 _strRejectReason 我使用 @Html.Hidden() 发送它们;但是控制器中的模型对象作为参数是空的,我的控制器是:

public ActionResult Reject(MakerTransactions MakerTransactions)
    {
        MakerCheckerUnitOfWorkBase _MakerCheckerUnitOfWorkBase = new MakerCheckerUnitOfWorkBase();
        MakerTransactions.RouteAgentsConfigsMaker = _MakerCheckerUnitOfWorkBase.RouteAgentsConfigsChecker.RejectMaker(MakerTransactions.id,MakerTransactions._strRejectReason);

        return View(MakerTransactions);
    }
4

1 回答 1

0
@using (Html.BeginForm("Reject", "Maker", FormMethod.Get))
{
 @Html.HiddenFor(model => model._strRejectReason)
 @Html.Hidden("id", item.Id);
 <p>@Html.ValidationMessage("CustomError", new { @style = "color:red" })</p>
 }

MVC 使用标签中的名称。然后,当您添加具有不同名称的标签 ID 时,服务器无法识别此属性。

@Html.HiddenFor(model => model._strRejectReasonm, new {id = "sample" })

public ActionResult Reject(FormCollection collection)
    {
        var _strRejectReason = collection["_strRejectReason"];
        var id = collection["id"];
        return View();
    }
于 2013-11-10T12:00:09.947 回答