MVC 5 Update Dropdown from Partial with AJax [duplicate]
This question already has an answer here:
Dynamically populate the drop-down using jQuery in ASP.Net MVC3
2 answers
After the Ajax fires the controller action FilterEngine()
, it passes the ViewBag.EngineID
to the partial view. When I debug the partial, I can see the ViewData
dictionary. However, the Dropdown is not updated.
What am I doing wrong?
View...
...
@Html.DropDownList("ManufacturerId", null, htmlAttributes: new { @class = "form-control-sm", id = "MFGDropdown" })
...
@{Html.RenderPartial("_engines");}
_engines.cshtml
@Html.DropDownList("EngineId", null, htmlAttributes: new { @class = "form-control-sm" })
JQuery
$("#MFGDropdown").change(function () {
var val = $(this).val();
$.ajax({
url: '/Admin/FilterEngine',
type: 'GET',
dataType: 'html',
cache: false,
data: { mfg: val },
success: function (response) {
},
error: function (x, e) {
if (x.status == 0) {
alert('You are offline!!n Please Check Your Network.');
} else if (x.status == 404) {
alert('Requested URL not found.');
} else if (x.status == 500) {
alert('Internel Server Error.');
} else if (e == 'parsererror') {
alert('Error.nParsing JSON Request failed.');
} else if (e == 'timeout') {
alert('Request Time out.');
} else {
alert('Unknow Error.n' + x.responseText);
}
}
});
AdminController
public ActionResult FilterEngine(string mfg)
{
var engines = db.Engines.Where(m => m.Manufacturer == mfg).Select(s => new SelectListItem { Text = s.Model, Value = s.Id.ToString() }).ToList();
ViewBag.EngineId = engines;
return PartialView("_engines");
}
c# jquery asp.net-mvc partial-views
marked as duplicate by Tetsuya Yamamoto, Community♦ Nov 21 at 17:33
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Dynamically populate the drop-down using jQuery in ASP.Net MVC3
2 answers
After the Ajax fires the controller action FilterEngine()
, it passes the ViewBag.EngineID
to the partial view. When I debug the partial, I can see the ViewData
dictionary. However, the Dropdown is not updated.
What am I doing wrong?
View...
...
@Html.DropDownList("ManufacturerId", null, htmlAttributes: new { @class = "form-control-sm", id = "MFGDropdown" })
...
@{Html.RenderPartial("_engines");}
_engines.cshtml
@Html.DropDownList("EngineId", null, htmlAttributes: new { @class = "form-control-sm" })
JQuery
$("#MFGDropdown").change(function () {
var val = $(this).val();
$.ajax({
url: '/Admin/FilterEngine',
type: 'GET',
dataType: 'html',
cache: false,
data: { mfg: val },
success: function (response) {
},
error: function (x, e) {
if (x.status == 0) {
alert('You are offline!!n Please Check Your Network.');
} else if (x.status == 404) {
alert('Requested URL not found.');
} else if (x.status == 500) {
alert('Internel Server Error.');
} else if (e == 'parsererror') {
alert('Error.nParsing JSON Request failed.');
} else if (e == 'timeout') {
alert('Request Time out.');
} else {
alert('Unknow Error.n' + x.responseText);
}
}
});
AdminController
public ActionResult FilterEngine(string mfg)
{
var engines = db.Engines.Where(m => m.Manufacturer == mfg).Select(s => new SelectListItem { Text = s.Model, Value = s.Id.ToString() }).ToList();
ViewBag.EngineId = engines;
return PartialView("_engines");
}
c# jquery asp.net-mvc partial-views
marked as duplicate by Tetsuya Yamamoto, Community♦ Nov 21 at 17:33
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Dynamically populate the drop-down using jQuery in ASP.Net MVC3
2 answers
After the Ajax fires the controller action FilterEngine()
, it passes the ViewBag.EngineID
to the partial view. When I debug the partial, I can see the ViewData
dictionary. However, the Dropdown is not updated.
What am I doing wrong?
View...
...
@Html.DropDownList("ManufacturerId", null, htmlAttributes: new { @class = "form-control-sm", id = "MFGDropdown" })
...
@{Html.RenderPartial("_engines");}
_engines.cshtml
@Html.DropDownList("EngineId", null, htmlAttributes: new { @class = "form-control-sm" })
JQuery
$("#MFGDropdown").change(function () {
var val = $(this).val();
$.ajax({
url: '/Admin/FilterEngine',
type: 'GET',
dataType: 'html',
cache: false,
data: { mfg: val },
success: function (response) {
},
error: function (x, e) {
if (x.status == 0) {
alert('You are offline!!n Please Check Your Network.');
} else if (x.status == 404) {
alert('Requested URL not found.');
} else if (x.status == 500) {
alert('Internel Server Error.');
} else if (e == 'parsererror') {
alert('Error.nParsing JSON Request failed.');
} else if (e == 'timeout') {
alert('Request Time out.');
} else {
alert('Unknow Error.n' + x.responseText);
}
}
});
AdminController
public ActionResult FilterEngine(string mfg)
{
var engines = db.Engines.Where(m => m.Manufacturer == mfg).Select(s => new SelectListItem { Text = s.Model, Value = s.Id.ToString() }).ToList();
ViewBag.EngineId = engines;
return PartialView("_engines");
}
c# jquery asp.net-mvc partial-views
This question already has an answer here:
Dynamically populate the drop-down using jQuery in ASP.Net MVC3
2 answers
After the Ajax fires the controller action FilterEngine()
, it passes the ViewBag.EngineID
to the partial view. When I debug the partial, I can see the ViewData
dictionary. However, the Dropdown is not updated.
What am I doing wrong?
View...
...
@Html.DropDownList("ManufacturerId", null, htmlAttributes: new { @class = "form-control-sm", id = "MFGDropdown" })
...
@{Html.RenderPartial("_engines");}
_engines.cshtml
@Html.DropDownList("EngineId", null, htmlAttributes: new { @class = "form-control-sm" })
JQuery
$("#MFGDropdown").change(function () {
var val = $(this).val();
$.ajax({
url: '/Admin/FilterEngine',
type: 'GET',
dataType: 'html',
cache: false,
data: { mfg: val },
success: function (response) {
},
error: function (x, e) {
if (x.status == 0) {
alert('You are offline!!n Please Check Your Network.');
} else if (x.status == 404) {
alert('Requested URL not found.');
} else if (x.status == 500) {
alert('Internel Server Error.');
} else if (e == 'parsererror') {
alert('Error.nParsing JSON Request failed.');
} else if (e == 'timeout') {
alert('Request Time out.');
} else {
alert('Unknow Error.n' + x.responseText);
}
}
});
AdminController
public ActionResult FilterEngine(string mfg)
{
var engines = db.Engines.Where(m => m.Manufacturer == mfg).Select(s => new SelectListItem { Text = s.Model, Value = s.Id.ToString() }).ToList();
ViewBag.EngineId = engines;
return PartialView("_engines");
}
This question already has an answer here:
Dynamically populate the drop-down using jQuery in ASP.Net MVC3
2 answers
c# jquery asp.net-mvc partial-views
c# jquery asp.net-mvc partial-views
edited Nov 21 at 3:15
Tetsuya Yamamoto
14.3k41939
14.3k41939
asked Nov 21 at 2:27
Beengie
7712825
7712825
marked as duplicate by Tetsuya Yamamoto, Community♦ Nov 21 at 17:33
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Tetsuya Yamamoto, Community♦ Nov 21 at 17:33
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
you are getting data but you need to add those options in your dropdown in your ajax success.
these answers might help you:
Populating dropdown with JSON result - Cascading DropDown using MVC3, JQuery, Ajax, JSON
ASP.NET MVC Html.DropDownList populated by Ajax call to controller?
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
you are getting data but you need to add those options in your dropdown in your ajax success.
these answers might help you:
Populating dropdown with JSON result - Cascading DropDown using MVC3, JQuery, Ajax, JSON
ASP.NET MVC Html.DropDownList populated by Ajax call to controller?
add a comment |
you are getting data but you need to add those options in your dropdown in your ajax success.
these answers might help you:
Populating dropdown with JSON result - Cascading DropDown using MVC3, JQuery, Ajax, JSON
ASP.NET MVC Html.DropDownList populated by Ajax call to controller?
add a comment |
you are getting data but you need to add those options in your dropdown in your ajax success.
these answers might help you:
Populating dropdown with JSON result - Cascading DropDown using MVC3, JQuery, Ajax, JSON
ASP.NET MVC Html.DropDownList populated by Ajax call to controller?
you are getting data but you need to add those options in your dropdown in your ajax success.
these answers might help you:
Populating dropdown with JSON result - Cascading DropDown using MVC3, JQuery, Ajax, JSON
ASP.NET MVC Html.DropDownList populated by Ajax call to controller?
answered Nov 21 at 2:49
Poonam Hirpara
3115
3115
add a comment |
add a comment |