我有一个查找人员控制回发以从AD获取官员信息。返回信息后,我取消隐藏包含信息的div。一切正常,直到我提交表格,并通过客户端验证。我遇到了以下问题。
@html.DisplayFor
帮助程序方法不包含任何信息。 @Html.HiddenFor
确实包含所有正确的信息。有没有办法让@html.DisplayFor
正常工作?拥有只读文本框是不够的,因为我只是在纯文本之后。
隐藏/显示是否有更好的方法。我的代码非常令人震惊,我确信有一种更好的方法可以在Postback和Client Side验证上运行吗?
<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);
}
}
}