我有一个在 PartialView 中呈现的时事通讯文本框。这是获取操作:
[ChildActionOnly]
public PartialViewResult NewsLetterSidebar()
{
return PartialView("_NewsLetterSidebar");
}
这是 Razor 视图:
model Blog.Web.UI.ViewModels.NewsLetterViewModel
@{
ViewBag.Title = "_NewsLetterSidebar";
}
@using (Html.BeginForm("NewsLetter", "Home", FormMethod.Post))
{
<h3>News Letter</h3>
<div>
@Html.TextBoxFor(news => news.EmailAddress)
@Html.ValidationMessageFor(news => news.EmailAddress)
</div>
<div>
<input type="submit" value="Verify">
</div>
}
如果输入有效,我希望成功消息显示在验证按钮下。这是我的帖子操作:
[HttpPost]
public JsonResult NewsLetter(NewsLetterViewModel newsLetter)
{
var newsLetterViewModel = newsLetter.ConvertToNewsLetterModel();
if (ModelState.IsValid)
{
_newsLetterRepository.Add(newsLetterViewModel);
_newsLetterRepository.Save();
}
return Json("Done!");
}
如何在视图下显示 JSON 消息?