1

I have an HTML select box called ddlLocation. When the value changes in the select box a change event javascript method gets fired. In the change event code, I want to assign the changed value to my ASP.NET variable called Model.Location.

I am trying to do this:

$("#ddlLocation").change(function (evt) {
    <%Model.Location =%> $('#ddlLocation option:selected').text();<%; %>
});

It keeps crashing and saying "Cannot implicitly convert type 'void' to 'string'"

Please Help!!!

1
  • you cannot do this , why not pass the selected value as a query string and bind it to a view model .. this happens usually on form submits Commented Feb 16, 2011 at 16:47

1 Answer 1

1

You can't do this that way. you have to post the value to a controller method that will assign the location.

$("#ddl3PVLocationSourceCodes").change(function (evt) {
   var locationValue = $('#ddlLocation option:selected').text();
   $.post("/YourController/AssignLocation", { location: locationValue });  
});

Hope it helps.

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.