Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have razor code. During the code, I want to pass two parameters to the controller.
One is from the model, the other one value is from the selected item from the drop down list.
$(document).ready(function () {
            $("#Languages").change(function () {
                var value = $(this).find('option:selected').val();
                @Html.Action("Index", "MyController",new{id=model.Guid, name= value);
            });
        });

But I get the error
the name 'value' does not exist in the current context


What I have tried:

google search
pass javascript variable to razor
Posted
Updated 8-Aug-17 2:52am

It is impossible... Anything after @ (the Razor opening) is handled on the server side, prior/during the page rendering... JavaScript belongs and exists on the client only...
 
Share this answer
 
Find a solution online. I should make an ajax call rather than using
@Html.Action
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900