Reputation: 734
I have to SelectList via DropDownListFor Html Helper in MVC like this:
@Html.DropDownListFor(m => m.ProjectType, @Model.ProjectTypeList, "Select One",
new { @id = "ProjectTypeList" })
The thing is that in jQuery I write:
alert($('#ProjectType').val());
And it gives me the correct value. But if I write this (right after that):
var programmeUrl = '/api/Programme/' + $('#ProjectType').val()
I get something like this:
SomeValue%20?_=1409153033527
So my WebAPI returns Not found since it is only expecting SomeValue. Any ideas why am I getting this. It is frustrating since I do the same for others and don't have this issue. Thanks in advance.
Upvotes: 0
Views: 419
Reputation: 3827
It's best not to use .val()
on a select list because clicking an option doesn't change the value of the dropdown, it just adds the :selected
property.
You should do it this way instead:
$('#ProjectType').find(":selected").val();
Upvotes: 1