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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -