How to Get HTML drop down list value from View to controller in MVC?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to Get HTML drop down list value from View to controller in MVC?



Small help required



1) I have created an html Dropdown in MVC view like this


<select name="Associateddl" id="Associateddl"></select>



2)I am appending the options to the dropdownlist using Jquery Ajax like


$.ajax(
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'customservice.asmx/getallmember',
dataType: 'JSON',
success: function (response)
var getData = JSON.parse(response.d);
console.log(getData.length);
if (getData.length > 0)
$("#msg").hide();
$.each(getData, function (i, item)
var optiontext = "";
optiontext = "<option value='" + item.Aid + "'>" + item.AMail + "</option>";
$("#Associateddl").append(optiontext);
);

else
$("#msg").append("<p style='color:red'><b>Currently there are no members ,Please Add !!</b></p>");

,
error: function (err)
//alert(err);

);



3)Now i want to retrive the dropdown selected value to controller from View.



My Model:


public class Event

[DisplayName("Event Name")]
[Required(ErrorMessage ="Event Name is Mandatory...")]
public string Eventname get; set;
[DisplayName("Event Year")]
[Required(ErrorMessage ="Enter the Year...")]
public int Year get; set;
[DisplayName("Associate ID")]
[Required(ErrorMessage ="Associate ID is required...")]
public string Associateddl get; set;



My Controller:


[HttpPost]
public ActionResult Index(Event eve)


string ename = eve.Eventname;
int eyr = eve.Year;
string eassociate = eve.Associateddl; //Here i want to retrive the dropdownselected Value

return View();



Please help me to get the Html dropdown seleted value to Controller from View.









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS