Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

jquery - Redirect on success and show error on failure -


i have implemented controller create new users. when creates user redirects index().

what want get redirected when ok, stay in current page , see error when failed.

i'm using jquery ajax mvc.

my controller looks this:

[authorize] public actionresult createuser(string username) {     try     {         //here logic create user     }        catch (exception ex)     {         string error = string.format("error creating user: {0}", ex.message);         response.statuscode = 500;         response.write(error);         }     return redirecttoaction("index"); } 

the form submit intercepted jquery, , call made ajax:

$("#new-user-form").submit(function() {     var form = $(this);     $.ajax({     type: "get",         url: form.attr('action'),         data: form.serialize(),         success: function(data, textstatus, xhr) {             //at point redirect         },         error: function(xhr, textstatus, errorthrown) {             $(".error-summary").html(xhr.responsetext);         }     });      //cancel event     return false; }); 

it works fine when error occurs, don't know how implement success case.

i'm opened other alternatives.

if going redirect in success action why using ajax? purpose of ajax refresh parts of site without reloading whole page. if in success action going redirect totally defeats purpose , benefits ajax. because asked here's do:

[authorize] public actionresult createuser(string username) {     ...     if (request.isajaxrequest())     {         return json(new { redirecttourl = url.action("index") });     }     return redirecttoaction("index"); } 

and then:

success: function(data, textstatus, xhr) {     window.location.href = data.redirecttourl; }, 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -