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)
Questions:
- 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
Have you tried checking your request in the request to your server to make sure it didn't escape?
It should look like
"/Tests/QuestionList?testId=1&Page=2"
I guess this escaped:
"/Tests/QuestionList?testId=1&Page=2"
If that's the problem, use the @ Html.Raw () helper. See MVC3 Url.Action querystring for a complete solution .
source to share
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.
source to share