使用电解法的Im似乎在装货时展示。 我没有任何东西可以自动提交表格,在我的控制人员中,在表格公布之前,没有进行验证检查。 充其量,验证似乎在提交时完美无缺。
观点:
[Validator(typeof(SendMessageInputValidator))]
public class SendMessageInput
{
public string Title { get; set; }
public string Content { get; set; }
public string VideoUrl { get; set; }
public string CultureName { get; set; }
public bool VideoMode { get; set; }
}
public class SendMessageInputValidator : AbstractValidator<SendMessageInput>
{
public SendMessageInputValidator()
{
RuleFor(s => s.Title)
.NotEmpty().WithMessage("TitleRequired".Translate("MCN"));
}
}
主计长:
public ActionResult Detail(Guid entityId, string cultureName)
{
var entity = _sendMessageRepository.Get(entityId);
if (entity == null)
throw new HttpException(404, "Not found.");
return View(new SendMessagePageViewModel
{
NodeId = entity.NodeId,
Name = entity.Name,
Title = entity.Title,
Content = entity.Content,
BrowserTitle = entity.BrowserTitle,
MetaDescription = entity.MetaDescription,
MetaKeywords = entity.MetaKeywords,
SendMessageInput = new SendMessageInput { VideoMode = true }
});
}
public ActionResult SendMessageForm(SendMessageInput input)
{
input.CultureName = Thread.CurrentThread.CurrentUICulture.Name;
return PartialView(/*input*/ new SendMessageInput());
}
[HttpPost]
public ActionResult SendMessage(SendMessageInput input)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(input.CultureName);
if (ModelState.IsValid)
{
return Redirect(Utilities.GetUrl(Constants.NodeIds.MyProfile));
}
var entity = _sendMessageRepository.Get(Constants.NodeIds.MentorQuestionForm);
if (entity == null)
throw new HttpException(404, "Not found.");
return PartialView("Detail", new SendMessagePageViewModel
{
NodeId = entity.NodeId,
Name = entity.Name,
Title = entity.Title,
Content = entity.Content,
BrowserTitle = entity.BrowserTitle,
MetaDescription = entity.MetaDescription,
MetaKeywords = entity.MetaKeywords,
SendMessageInput = input
});
}
观点(主要):
@Html.Action("SendMessageForm", "SendMessage", Model.SendMessageInput)
观点(部分):
@Html.ValidationSummary(false, "ValidationSummaryHeader".Translate("MCN"))
@using (Html.BeginForm("SendMessage", "SendMessage", FormMethod.Post))
{
<div class="Formulaire">
<p>
@Html.LabelFor(m => m.Title, "Title".Translate("MCN"), true)
@Html.TextBoxFor(m => m.Title, new { maxlength = 200, @class = "TxtBox" })
</p>
@if (Model.VideoMode)
{
<p>
@Html.LabelFor(m => m.VideoUrl, "VideoUrl".Translate("MCN"))
@Html.TextBoxFor(m => m.VideoUrl)
</p>
}
else
{
<p>
@Html.LabelFor(m => m.Content, "Message".Translate("MCN"))
@Html.TextAreaFor(m => m.Content, new { @class = "TxtArea" })
</p>
}
@Html.HiddenFor(m => m.CultureName)
<input type="submit" value="@("Submit".Translate("MCN"))"/>
</div>
}