我有一个查找官员控件,可以回发以从 AD 获取官员信息。返回信息时,我取消隐藏包含信息的 div。一切正常,直到我提交表单并通过客户端验证。我遇到以下问题。
- 当我提交表单进行客户端验证时,
@html.DisplayFor
辅助方法不包含任何信息。@Html.HiddenFor
确实包含所有正确的信息。 - 此外,同时我的隐藏和显示不再起作用。
有没有办法开始@html.DisplayFor
工作?拥有一个只读文本框是不够的,因为我只是在纯文本之后。
有没有更好的隐藏/显示方法。我拥有的代码非常令人震惊,我确信有更好的方法可以同时用于回发和客户端验证?
<div class="row-fluid">
<div class="span3">
@Html.LabelFor(model => model.RequestingPayroll)
</div>
<div class="span4">
<div class="input-append">
@Html.TextBoxFor(model => model.RequestingPayroll, new { @class = "span6", placeholder = "payroll" })
<button type="submit" id="btnSubmit" name="Command" value="FindOfficer" class="btn cancel">Find Officer</button>
</div>
@Html.ValidationMessageFor(model => model.RequestingPayroll)
</div><!--/span-->
</div>
@if (Model != null)
{
if (Model.RequestingFirstName != "" && Model.RequestingFirstName != null)
{
ViewBag.RequestingPayroll = "";
}
else
{
ViewBag.RequestingPayroll = "hide";
}
}
else
{
ViewBag.RequestingPayroll = "hide";
}
<div id="requesting-payroll" class="row-fluid row-form @ViewBag.RequestingPayroll">
<div class="offset3 span9">
<div class="alert alert-info">
<strong><span class="capitalise">@Html.DisplayTextFor(model => model.RequestingLastName)</span>, @Html.DisplayTextFor(model => model.RequestingFirstName) (@Html.DisplayTextFor(model => model.RequestingRank))</strong><br />
@Html.DisplayTextFor(model => model.RequestingStationUnit) <br />
<strong>phone:</strong> @Html.DisplayTextFor(model => model.RequestingPhone), <strong>mobile:</strong> @Html.DisplayTextFor(model => model.RequestingMobile)
@Html.HiddenFor(model => model.RequestingLastName)
@Html.HiddenFor(model => model.RequestingFirstName)
@Html.HiddenFor(model => model.RequestingRank)
@Html.HiddenFor(model => model.RequestingStationUnit)
@Html.HiddenFor(model => model.RequestingPhone)
@Html.HiddenFor(model => model.RequestingMobile)
</div>
</div>
</div>
这是我的控制器代码
[HttpPost]
public ActionResult Index(DPACS.Models.Request request, string Command)
{
if (Command == "FindOfficer")
{
QpsUser user = CommonMethods.FindQpsUser(request.RequestingPayroll.ToString());
if (user != null)
{
ModelState.Clear();
request.RequestingRank = user.Rank;
request.RequestingFirstName = user.FirstName;
request.RequestingLastName = user.LastName;
request.RequestingPhone = user.PhoneNumber;
request.RequestingMobile = user.MobileNumber;
request.RequestingStationUnit = user.Station;
return View(request);
}
}
}