Setup DropDownListFor in Create view to use for states and form won't submit

Setup DropDownListFor in Create view to use for states and form won’t submit.

Here is the controller code:

‘<<<(STATE DROP-DOWN)>>>
Dim ListStates As List(Of KeyValuePair(Of String, String)) = FormItems.GetStates()
Dim States As New List(Of SelectListItem)()

For Each item As KeyValuePair(Of String, String) In ListStates
States.Add(New SelectListItem() With {.Text = item.Key, .Value = item.Value})
Next
ViewBag.State = States

‘>>>>>>>>>>>>>>>>>>

The controller code works fine and builds the dropdown list in the create view; here is the line in the create view:

@Html.DropDownListFor(Function(model) model.State, ViewBag.State)

I pick a state and fill out the other parts of the form and click create but it won’t submit and highlights the state dropdown.

What could be the problem?

Hi belcherman,

Do you mean the data of DropDownList is not submit?

If that is the case, how do you receive that data? The action code may like this below:

public ActionResult Index([your model] m)
{

}
public ActionResult Index(string state)
{

}

Please use the developer to check the posted data whether the necessary data have been submitted.

Best Regards

Starain Chen

Leave a Reply