I have the following URL: https://localhost:27635/Student/Create?PersonId=1
I also have a combobox filled with Persons which the user can use to select a Person. How can I set the combobox to have by default the PersonId from the URL?
This is the combobox code:
@Html.DropDownListFor(
x => x.PersonId,
new SelectList(Model.Persons, "Id", "Fullname", Model.PersonId),
"-- Select --", new { @class = "form-control" }
)
It contains PersonIds, displaying the full name. The reason I want to use a combobox instead of saving the value from the URL directly is because I want to allow the user to change.
Another thing im curious about is if its possible to have the default -- Select --
show up if the URL id is incorrect and not in the combobox.
Thanks