Gma*_*n16 5 c# asp.net-mvc dialog showmodaldialog
使用MVC框架与C#编码.视图以标准HTML代码编写.一旦用户单击提交按钮,我需要一条确认消息"您的消息已被发送"
这是控制器:
public ActionResult Index(ContactViewModel contactVM){
if (!ModelState.IsValid)
{
string url = Request.UrlReferrer.AbsolutePath+ "#contact";
return View();
}
else
{
var contact = new Contact
{
Name = contactVM.Name,
Email = contactVM.Email,
Subject = contactVM.Subject,
Message = contactVM.Message
};
new Email().Send(contact);
return RedirectToAction("Index");
}
Run Code Online (Sandbox Code Playgroud)
这是视图:
<input type="submit" class="submit_btn left" name="Submit" id="submit" value="Submit"/>
<input type="reset" class="submit_btn right" name="Reset" id="reset" value="Reset" />
Run Code Online (Sandbox Code Playgroud)
请帮助.
Ehs*_*jad 13
而不是RedirectToAction(),返回View:
new Email().Send(contact);
ViewBag.Message = "Message Sent";
return View();
Run Code Online (Sandbox Code Playgroud)
在视图中:
@if(ViewBag.Message != null)
{
<script>
$(document).ready(function(){
alert('@ViewBag.Message');
});
</script>
}
Run Code Online (Sandbox Code Playgroud)