我的视图中有这段代码
@using (Html.BeginForm("Add", "AdminUsers"))
{
<div class="control-group">
<span class="control-label">* Role:</span>
<div class="controls">
<select name="Role">
<option value="@Argussite.SupplierService.Core.Domain.Role.Manager"
@if (Model.Role == Argussite.SupplierService.Core.Domain.Role.Manager) { <text>selected="selected"</text> }>
@Argussite.SupplierService.Core.Domain.Role.ManagerTitle</option>
<option value="@Argussite.SupplierService.Core.Domain.Role.ChiefManager"
@if (Model.Role == Argussite.SupplierService.Core.Domain.Role.ChiefManager) { <text>selected="selected"</text> }>
@Argussite.SupplierService.Core.Domain.Role.ChiefManagerTitle</option>
<option value="@Argussite.SupplierService.Core.Domain.Role.Ceo"
@if (Model.Role == Argussite.SupplierService.Core.Domain.Role.Ceo) { <text>selected="selected"</text> }>
@Argussite.SupplierService.Core.Domain.Role.CeoTitle</option>
</select>
</div>
</div>
//...
<div class="control-group">
<span class="control-label">* Phone:</span>
<div class="controls">
@Html.TextBoxFor(m => m.PhoneNumber)
@Html.ValidationMessageFor(m => m.PhoneNumber, null, new {@class="text-error"})
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">Add</button>
<a href="@Url.Action("Index", "AdminUsers")" class="btn">Cancel</a>
</div>
</div>
}
如果我在列表中选择,我需要添加一个检查
Model.Role == Argussite.SupplierService.Core.Domain.Role.Manager
我需要展示
<div class="control-group">
<span class="control-label">* Phone:</span>
<div class="controls">
@Html.TextBoxFor(m => m.PhoneNumber)
@Html.ValidationMessageFor(m => m.PhoneNumber, null, new {@class="text-error"})
</div>
</div>
如果我更改了列表中的选定值
Model.Role == Argussite.SupplierService.Core.Domain.Role.ChiefManager
或者
Model.Role == Argussite.SupplierService.Core.Domain.Role.Ceo
我需要显示没有 * 的电话字段,并且我不需要验证此字段。
我怎样才能做到这一点?
这是我的控制
[HttpPost]
public ActionResult Add(AddArgussoftUserInput input)
{
if ((input.Role == Role.Manager || input.Role == Role.ChiefManager) && string.IsNullOrWhiteSpace(input.PhoneNumber))
{
ModelState.AddModelError("PhoneNumber", "Please, provide a valid Phone Number");
}
if (!Context.IsUserNameUnique(input.Name))
{
ModelState.AddModelError("Name", AddArgussoftUserInput.NameIsNotUniqueError);
}
if (!Context.IsUserEmailUnique(input.Email))
{
ModelState.AddModelError("Email", AddArgussoftUserInput.EmailIsNotUniqueError);
}
if (!ModelState.IsValid)
{
return View(input);
}
var user = new User(input.Name, input.Email, input.FullName, input.Role, input.PhoneNumber);
Context.Users.Add(user);
Register(new UserCreatedNotification(user, null /* supplier */, UrlBuilder));
TriggerPopupSuccess(string.Format("Account '{0}' for user {1} has been created.", input.Name, input.FullName));
return RedirectToAction("Index");
}