Pass multiple values ​​from View to Action

I have the following piece of code and I have 3 questions related to it:

JScript in view:

$('#page1').load('@Url.Action("QuestionList", "Tests", new { testId = Model.Test.ID , Page = 2 })');


Action in Test Controller:

public ActionResult QuestionList(int testId, int Page)
        // some meaningless operations here
        return PartialView("QuestionList", somevalue);


(Partial view also QuestionList - I tried with a different name just to be safe - and it didn't work again)


  • When using testId alone, everything is fine. Now when I added the page, the Parameter Page is always null.
  • I created a model that was supposed to replace two variables. The new model is always zero.
  • The third question is not related to the title, but to the current problem - how to pass the value from the view to the Url.Action method? I know the method is server side and the view with JScript is on the client, but with this last problem I have to solve, I'm just lost.

I have already checked threads like this one: Pass multiple values ​​from view , but the suggested solution is actually my problem.

Any help would be greatly appreciated.


source to share

2 answers

Have you tried checking your request in the request to your server to make sure it didn't escape?
It should look like



I guess this escaped:



If that's the problem, use the @ Html.Raw () helper. See MVC3 Url.Action querystring for a complete solution .



First: how did you go through your model? I had a problem similar to yours when using MVCContrib grid. I tried to send data like column and order by instantiating a new object, but that didn't help. Instead of passing an MVCContrib.Options object like this @Url.Action("QuestionList", "Tests", new { testId = Model.Test.ID , Page = 2, options = new MVCContrib.Options() })

, I had to send the class properties name: @Url.Action("QuestionList", "Tests", new { testId = Model.Test.ID , Page = 2, Column="xxx", Order=Ascending })

or something like that.

Also, it looks like you are building your link correctly. Just in case, put "@" in front of Page

it, it might be a reserved word.



All Articles