Generating an action URL in JavaScript for ASP.NET MVC

前端 未结 9 1152
梦毁少年i
梦毁少年i 2020-12-09 09:52

I\'m trying to redirect to another page by calling an action in controller with a specific parameter. I\'m trying to use this line:

window.open(\'<%= Url.         


        
9条回答
  •  被撕碎了的回忆
    2020-12-09 10:14

    Could you do

    window.open('/report/survey/' + selectedRow);
    

    instead where selected row I assume is the id? The routing should pick this up fine.

    or use getJSON

    Perhaps you could use JSONResult instead. Wherever the window.open should be call a method instead i.e. OpenSurveyWindow(id);

    then add some jquery similar to below

    function OpenSurveyWindow(id){
          $.getJSON("/report/survey/" + id, null, function(data) {
              window.open(data);
         });
    }
    

    now in your controller

    public JsonResult Survey(int id)
    {
        return Json(GetMyUrlMethod(id));
    }
    

    That code isnt syntactically perfect but something along those lines should work

提交回复
热议问题