javascript - Can't redirect to new page Ajax beginform -
i have ajax.beginform-code:
<script> function createsuccess(data) { if (data.redirecturl) { window.location.href = data.redirecturl; } } </script> @using (ajax.beginform("new", "profile", null, new ajaxoptions() { httpmethod = "post", insertionmode = insertionmode.replace, onsuccess = "createsuccess" })) { @html.antiforgerytoken() @html.validationsummary(true, "", new { @class = "text-danger" }) //html-code }
here new action in profile controller:
[httppost] public actionresult new(profile model) { model.userid = userid; if (_profileservice.createprofile(model) > 0) { var encryptedprofileid = encryption.protect(model.profileid.tostring(), userid.tostring()); response.cookies["profileid"].value = encryptedprofileid; return json(new { redirecturl = url.action("index", "welcome") }); } return view(); }
when run , tries create new profile, not redirect. instead, redirected new-page following json displayed:
why not redirected? can me?
add "jquery.unobtrusive-ajax.js" page. if you're using "bundling" feature in system.web.optimization, 1 easy way add jquery bundle:
bundles.add(new scriptbundle("~/bundles/jquery") .include("~/scripts/jquery-{version}.js") .include("~/scripts/jquery.unobtrusive-ajax.js"));
you can add <script>
tag points script.
Comments
Post a Comment