我想在mvc 4中获取DDL值时出现500内部错误 它会运行,并给我类似波纹管的产品ID,但不会向我显示Porduct详细信息: http://localhost:24494/Merchant/GetProduct?id=14
控制者:
[HttpGet]
public PartialViewResult GetProduct(int id)
{
ProductRepository BlProduct = new ProductRepository();
var model = BlProduct.Find(id);
return PartialView("_CampProductPartialView", model);
}
部分:
@model CrazyAvocado.ViewModels.Merchant.AddCampaignViewModel
<div class="display-field">
@Html.DisplayFor(model => model.Product.Name)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.Product.Price)
</div>
视图:
@using (Html.BeginForm("AddCampaign", "Merchant", FormMethod.Post, new { enctype = "multipart/form-data", id = "myUploadForm" }))
下拉列表:
@Html.DropDownListFor(x => Model.Campaign.Productid, new SelectList(Model.Products, "id", "Name"), htmlAttributes: new { @class = "form-control", id = "ProductsDDL" })
包含该内容的细分应该显示详细信息: Div ID为“ divPartialView”
@Html.Partial("_CampProductPartialView")
最后是Jquery脚本
<script>
$("#ProductsDDL").change(function (event) {
var ProductId = $(this).val();
$.ajax({
url: "@Url.Action("GetProduct", "Merchant")",
data: { id: ProductId },
type: "Get",
dataType: "html",
success: function (data) {
//Whatever result you have got from your controller with html partial view replace with a specific html.
$("#divPartialView").html(data); // HTML DOM replace
}
});
});
</script>