c# - Doesn't show view from controller even debugger goes inside View -
i new in mvc .net. not able call view controller. have debug flow. goes view doesn't show view on screen.
controller name: downloads action name: makepayment redirect view: success //success view of view/downloads/success.cshtml
code: downloadscontroller
[httppost] public actionresult makepayment(downloads ccm) { if (true) { return view("success"); } else { return view("failure"); } }
view
@{ viewbag.title = "success"; } <h2>your transaction has been completed successfully.</h2>
method use call actionresult makepayment. had use ajax here because wanted call javascript function before form submit.
view: index.cshtml @using (ajax.beginform("makepayment", "downloads", new ajaxoptions { httpmethod = "post", insertionmode = insertionmode.replace, onbegin = "paybycreditcard" })) { //submit button }
according return view("success");
, should call view. in fact when debug flow, goes success view doesn't display view on screen. keeps old view on screen.
degug route after success: _viewstart-->success.cshtml-->_layout.cshtml.
can suggest me if missing something?
since making ajax call using ajax.beginform
helper method, need specify response (of ajax call) replaced in dom. can specify using updatetargetid
property
@using (ajax.beginform("makepayment", "downloads", new ajaxoptions { httpmethod = "post", insertionmode = insertionmode.replace, updatetargetid="yourdivtoshowresult" onbegin = "paybycreditcard" })) { <div id="yourdivtoshowresult"></div> <input type="submit" /> }
since ajax call, not redirect. instead,it update content of div (with id yourdivtoshowresult) in same page response coming markup returned success view.
also since showing partial page update, might consider returning partial view.
[httppost] public actionresult makepayment(downloads ccm) { if (everything good) { return partialview("success"); } else { return partialview("failure"); } }
this return markup either of views without layout.
Comments
Post a Comment