0
我想在MVC应用程序中使用类似于Exit sub
的动作,我使用的是c#语言。如何在MVC中退出函数?
当我只输入return
它显示一个错误。其要求强制ActionResult
。
[HttpPost]
public ActionResult Create(Location location)
{
if (ModelState.IsValid)
{
Validations v = new Validations();
Boolean ValidProperties = true;
EmptyResult er;
string sResult = v.Validate100CharLength(location.Name, location.Name);
if (sResult == "Accept")
{
ValidProperties = true;
}
else
{
//What should I write here ?
//I wan to write return boolean prperty false
// When I write return it asks for the ActionResult
}
if (ValidProperties == true)
{
db.Locations.Add(location);
db.SaveChanges();
return RedirectToAction("Index");
}
}
ViewBag.OwnerId = new SelectList(
db.Employees, "Id", "FirstName", location.OwnerId);
return View(location);
}
如果sResult!=“Accept”,你想要什么?这是否意味着验证失败?如果它是真的,那么你需要向ModelState添加错误消息并返回View(位置)。 – 2012-08-01 14:17:19