javascript - How to show success message after insertion through form submitting -
i want show success message when insertion complete.here code
[httppost] public actionresult create(string txthospitalname, int city) { var hospitals = new hospital() { name = txthospitalname, fkcityid = city, createdat = datetime.now, createdby = 1, }; _db.hospitals.add(hospitals); _db.savechanges(); return redirecttoaction("create"); }
view.cshtml
@using (html.beginform("create", "hospital", formmethod.post, new {enctype = "multipart/form-data", id = "hospitalform"})) { //text fields }
using tempdata ideal post-redirect-get pattern.
your post action:
[httppost] public actionresult create(string txthospitalname, int city) { var hospitals = new hospital() { name = txthospitalname, fkcityid = city, createdat = datetime.now, createdby = 1, }; _db.hospitals.add(hospitals); _db.savechanges(); tempdata["success"] = true; return redirecttoaction("create"); }
your action:
[httpget] public actionresult create() { viewbag.success = tempdata["success"] bool; return view(); }
your view:
@if (viewbag.success != null && viewbag.success) { <h2> success message here</h2> } @using (html.beginform("create", "hospital", formmethod.post, new {enctype = "multipart/form-data", id = "hospitalform"})) { //text fields }
Comments
Post a Comment