Home > Blockchain >  C# MVC Not able to save item list from Dropdown
C# MVC Not able to save item list from Dropdown

Time:02-21

I have a custom <select> HTML statement with items. Unfortunately, upon submitting the form, the data is not pushed to the database but rather rendered as NULL.

Partial Code segment is as below:

<select name="RootCause" id="RootCause" >

@if (Model.RequestType == "Membership" || Model.RequestType == "Membership/Registration" || Model.RequestType == "General Enquiries")
{
<option value="Collaboration tool error">Collaboration tool error</option>
<option value="Syntax system error">Syntax system error</option>
}

The field RootCause is where the values should be populated into.

Any assistance would be appreciated.

CodePudding user response:

[HttpPost]
public ActionResult ActionName(FormCollection form)
{           
  string RootCause = form["RootCause"];
  return View();
}

By using FormCollection we can easily captured the value of RootCause field.

  • Related