1

I have the following code inside my razor view:-

@Html.PagedListPager(Model , page => Url.Action("Index","Server", new 
{
    searchTerm = ViewBag.searchTerm,
    page,
    sort = ViewBag.CurrentSortOrder,
    pagesize =  $("#pagesize").val()  
}),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(PagedListRenderOptions.ClassicPlusFirstAndLast, 
new AjaxOptions 
{
    UpdateTargetId = "ServerTable" , 
    LoadingElementId="progress2" 
}))

But i am unable to get the value of field using the following $("#pagesize").val(), so can anyone adivce if i can use a javaScript like syntax inside an Html helper ? Thanks

2
  • Indent your code a bit, this horizontal scrolling is really unhelpful. Commented May 2, 2014 at 15:46
  • 2
    No, you cannot use jQuery within server side code. Commented May 2, 2014 at 15:47

1 Answer 1

1

The answer is : NO WAY!

Because:

You cannot pass anything from javascript to razor without going through the server.

That is because the razor is executed server side (hence the c# in it). The controller is called, that class is instantiated, then the method is invoked which matches the action requested, and then a view is returned. When the view is returned, the c# code in the view is executed. Once all code has been executed, it issues the html page in the response and then the javascript runs on the client. For you to get from javascript to razor, you would have to issue a new request to go through that path from the beginning in order to come back out in the end.

Solve this issue server side.

More detailed information please see this link:

Pass js variable or inout value to razor

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.