asp.net mvc - How to return View from action when the request is always asynchronous -


i have action following definition in mvc:

 public actionresult create(club club)     {                if (modelstate.isvalid)         {             club clubfound = db.clubs.firstordefault(x => x.clubname == club.clubname);              if (clubfound != null)             {                 viewbag.countryid = new selectlist(db.countries.orderby(x => x.countryname), "countryid", "countryname");                 modelstate.addmodelerror("", "the club exists in database.");                 return view();             }             else             {                 db.clubs.add(club);                 db.savechanges();                 string message = mvchtmlstring.create(@"club added db successfully. <a href=""/"">go home page.</a>").tostring();                 //tempdata["successmessage"] = "club added.";                 return json(message, jsonrequestbehavior.allowget);             }         }          return view();                } 

if data fine, method executes , ok. when there model error , action returns view actially returns @ within view have 1 view in another. question how return view errors in normal post request? data coming view ajax form request asynchronous.

i guess should return model , return same view action triggered. you're adding error model, have return view, guess might have add @html.validationsummary() view.

something like:

public actionresult create(club club) {            if (modelstate.isvalid)     {         club clubfound = db.clubs.firstordefault(x => x.clubname == club.clubname);          if (clubfound != null)         {             viewbag.countryid = new selectlist(db.countries.orderby(x => x.countryname), "countryid", "countryname");             modelstate.addmodelerror("", "the club exists in database.");             return view(club);         }         else         {             db.clubs.add(club);             db.savechanges();             string message = mvchtmlstring.create(@"club added db successfully. <a href=""/"">go home page.</a>").tostring();             //tempdata["successmessage"] = "club added.";             return json(message, jsonrequestbehavior.allowget);         }     }      return view(club);            } 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -