Fill in the text boxes by selecting the dropdown in mvc

I want to fill in text boxes that are taking data from a database. When I select any value using the dropdown, I need to get the id from the dropdown and I call the function that populates @Html.EditorFor(model => model.taskName)

. The page will not change. How is this possible?

<div class="form-group">
      @Html.LabelFor(model => model.jobID, "jobID", new { @class = "control-label col-md-2" })
       <div class="col-md-10">
      @Html.DropDownList("jobID", String.Empty)
      @Html.ValidationMessageFor(model => model.jobID)
     <div> @Html.Partial("../Location/taskname") </div>



    <div class="form-horizontal">
        <div class="form-group">
            @Html.LabelFor(model => model.taskName, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.taskName)
                @Html.ValidationMessageFor(model => model.taskName)



source to share

1 answer

Make your dropdown like this:

@Html.DropDownList("jobID", null, new {@id="job"})


and the taskname textbox:

@Html.EditorFor(model => model.taskName, new {@id="taskname"})


do the following: write a jquery event for dropdown index change event and send ajax call to get task name against task id selected from dropdown:


var JobId =$(this).val();

// Send Ajax call and get Task name

var Url = ''+JobId ;

         url:    Url ,
         success: function(result) {
         error: function(error) {






All Articles