asp.net mvc - MVC inquiry, controller checks condition, stay on current page -


so controller has return view. i'm wondering professional approach in scenario?

controller checks condition, if true, proceeds, if false, pops message, stays on current page? thanks.

so "delete" action link on "index" view, when click on "delete" link, check condition on "delete" controller, if false, want stay on "index" view. controller has return something.

i redirected current page ("index" view), flashes, , browser embedded message box rather rough.

from controller method can return either view, file, partialview, json or more. if want page stay there without refreshing, suggestion use ajax submit request , return json.

in view:

<script type="text/javascript"> function dosomething() {         $.ajax({             datatype: "json",             url: '@url.action("dosomething", "yourcontrollerclass")/?parameter=dummy',             success: function (data) {                  alert(data.message);             },             async: false         });     } } </script> 

in controller:

public actionresult dosomething(string parameter)     {         //... stuff          return json(new { message = "your return message..." }, "text/plain", jsonrequestbehavior.allowget);     } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -