我是mvc的新手,我希望从文本框值背后的代码中访问一个值,我认为这是通过将值作为参数传递给我的操作结果但是当我调试时的逻辑方式firstName显示为null?。
这是我想要访问的价值,请原谅我的无知,我来自长长的网页背景。
std::uniform_real_distribution(0, std::nextafter(1.,2.));
关于控制器的快速问题我必须总是返回一个视图,它是从我可以调用的,例如,只要它有相同的布局文件就返回step2吗?除了我要问的保存操作原因之外,如何告诉它进入另一个视图我正在做一个向导表单。
我的表单标记
<input id="firstName" class="form-control" type="text" />
我的控制器操作结果:
@using (Html.BeginForm("Step1", "Forms", FormMethod.Post, new { id = "submitForm" }))
{
@Html.AntiForgeryToken()
<h4>Health Check</h4>
<hr />
@Html.ValidationSummary("", new { @class = "text-danger" })
<div class="form-group">
@Html.Label("First Name", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<input id="firstName" class="form-control" type="text" />
</div>
</div>
<div class="form-group">
@Html.Label("Middle Name", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<input id="txtmiddleName" class="form-control" type="text" />
</div>
</div>
<div class="form-group">
@Html.Label("Surname", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<input id="txtsurname" class="form-control" type="text" />
</div>
</div>
<div class="form-group">
@Html.Label("Saluation", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<input id="txtSaluation" class="form-control" type="text" />
</div>
</div>
<div class="form-group">
@Html.Label("Aliases", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<input id="txtAliases" class="form-control" type="text" />
</div>
</div>
<div class="form-group">
@Html.Label("Maritial Status", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<input id="txtmStatus" class="form-control" type="text" />
</div>
</div>
<div class="form-group">
@Html.Label("Maritial Status", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<select class="form-control"></select>
</div>
</div>
<div class="form-group">
@Html.Label("Address 2", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<input id="txtmStatus" class="form-control" type="text" />
</div>
</div>
<div class="form-group">
@Html.Label("City", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<input id="txtmStatus" class="form-control" type="text" />
</div>
</div>
<div class="form-group">
@Html.Label("Post Code", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<input id="txtmStatus" class="form-control" type="text" />
</div>
</div>
<div class="form-group">
@Html.Label("County", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<input id="txtCounty" class="form-control" type="text" />
</div>
</div>
<div class="form-group">
@Html.Label("Country", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<input id="txtmStatus" class="form-control" type="text" />
</div>
</div>
<div class="form-group">
@Html.Label("Date Of Birth", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@(Html.Kendo().DatePicker()
.Name("datepicker"))
</div>
</div>
<div class="form-group">
@Html.Label("Home Tel No", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<input id="txtmStatus" class="form-control" type="text" />
</div>
</div>
<div class="form-group">
@Html.Label("Home Work No", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<input id="txtmStatus" class="form-control" type="text" />
</div>
</div>
<div class="form-group">
@Html.Label("Fax No", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<input id="txtmStatus" class="form-control" type="text" />
</div>
</div>
<div class="form-group">
@Html.Label("Mobile No", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<input id="txtmStatus" class="form-control" type="text" />
</div>
</div>
<div class="form-group">
@Html.Label("Best Time To Call", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<select class="form-control">
<option>Morning</option>
<option>Afternoon</option>
<option>Evening</option>
</select>
</div>
</div>
<button type="submit" id="btnSave">Save</button>
}
答案 0 :(得分:2)
对于HTML中提交数据的任何表单,所有<input>
代码都必须具有name="..."
属性。设置id
对于javascript很有用,但是对于表单提交会被忽略。
在这种情况下,name="firstName"
将是一个良好的开端,因为它与您在Controller操作方法Step1
中绑定的内容相匹配。