#Ya lo resolví por si alguien necesita algo similar en un futuro#
controladorControlador
public JsonResult ArticulosPorCategoria(int Id )
{
var articulos = db.articulo.ToList().Where(p => p.Id_Categoria == Id);
return Json(new SelectList(articulos, "Id", "Nombre"));
}
public JsonResult ArticulosPorCategoria(int Id )
{
var articulos = db.articulo.ToList().Where(p => p.Id_Categoria == Id);
return Json(new SelectList(articulos, "Id", "Nombre"));
}
<script type="text/javascript">
$(document).ready(function () {
$("#Categoria").change(function () {
$("#Articulo").empty();
$.ajax({
type: 'POST',
url: '@Url.Action("ArticulosPorCategoria")',
dataType: 'json',
data: { id: $("#Categoria").val() },
success: function (articulos) {
$.each(articulos, function (i, articulo) {
$("#Articulo").append('<option value="' + articulo.Value + '">' +
articulo.Text + '</option>');
});
},
})
});
});
</script>
@Html.DropDownList("Categoria", ViewBag.Categoria as SelectList,htmlAttributes: new { @class = "form-control" })
@Html.DropDownList("Articulo", ViewBag.Artics as SelectList,htmlAttributes: new { @class = "form-control" })
<script type="text/javascript">
$(document).ready(function () {
$("#Categoria").change(function () {
$("#Articulo").empty();
$.ajax({
type: 'POST',
url: '@Url.Action("ArticulosPorCategoria")',
dataType: 'json',
data: { id: $("#Categoria").val() },
success: function (articulos) {
$.each(articulos, function (i, articulo) {
$("#Articulo").append('<option value="' + articulo.Value + '">' +
articulo.Text + '</option>');
});
},
})
});
});
</script>
@Html.DropDownList("Categoria", ViewBag.Categoria as SelectList,htmlAttributes: new { @class = "form-control" })
@Html.DropDownList("Articulo", ViewBag.Artics as SelectList,htmlAttributes: new { @class = "form-control" })