post action for url.action?

前端 未结 3 1188
旧时难觅i
旧时难觅i 2020-12-09 17:20

Here is a line of code in my Controller class:

return JavaScript(String.Format(\"window.top.location.href=\'{0}\';\", Url.Action(\"MyAction\", \"MyController         


        
3条回答
  •  一生所求
    2020-12-09 17:32

    Continuing off of Matt Lacey's answer, your action could return a bit of Javascript that does this:

    1. Use jquery to add a new form to the DOM
    2. Use jquery to submit the newly added form

    Something like this: (untested code)

    var urlHelper = new UrlHelper(...);
    var redirectUrl = urlHelper.Action("MyAction", "MyController");
    
    var redirectScript = String.Format(@"
        var formTag = $('
    '); $(body).append(formTag); formTag.submit();" , redirectUrl ); return JavaScript(redirectScript);

提交回复
热议问题