如何在BeginForm中传递MVC路由对象中的隐藏字段值

时间:2014-11-26 04:03:02

标签: javascript asp.net-mvc angularjs

我有一个文本框和一个按钮,如下所示。在hdnCityAreaService中,我设置用户将在js中callBack($item,$model,$label)内的角度预先输入文本框中选择的项目的ID。

@using (Html.BeginForm("TestAction", "Customer", FormMethod.Post, 
  new { strTest = "@hdnCityAreaService.value to be passed here" }))
  { 
    <div data-ng-app="v">
      <div ng-controller="TypeAheadController">
        <input type="text" id="txtType" ng-model="selected" typeahead-on-select="callBack($item,$model,$label)" typeahead="state as state.Name for state in states | filter:$viewValue | limitTo:8" class="form-control">
        @Html.Hidden("hdnCityAreaService")
        <input type="submit" id="sub" name="sub" value="click"/>
      </div>
    </div>
  }

我的TestAction看起来像:

public ActionResult TestAction(string strTest)
{
  return View();
}

我想发送&#34; hdnCityAreaService&#34;的值路由值对象,以便它将出现在Action中的strTest参数中。除了使用FormCollection之外,我该怎么做?

1 个答案:

答案 0 :(得分:0)

根据Stephen Muecke的建议修改下面的代码:

@using (Html.BeginForm("TestAction", "Customer", FormMethod.Post))
{ 
<div data-ng-app="v">
    <div ng-controller="TypeAheadController">
        <input type="text" id="txtType" ng-model="selected" typeahead-on-select="callBack($item,$model,$label)" typeahead="state as state.Name for state in states | filter:$viewValue | limitTo:8" class="form-control">
        @Html.Hidden("hdnCityAreaService")
        <input type="submit" id="sub" name="sub" value="click"/>
    </div>
</div>
}

public void TestAction(string hdnCityAreaService)
        {
            ReturnView();
        }