我正在尝试使用Ajax将模型传递给控制器/操作。但是在我的操作中,我将所有模型值都设为null。不知道我在这里做错了什么。我的模特是
DepartmentProductViewModel
public class DepartmentProductViewModel
{
public string SelectedProductCategory { get; set; }
public string[] FilterHouse { get; set; }
public string[] FilterBrand { get; set; }
public string[] FilterSize { get; set; }
public string[] FilterGender { get; set; }
public string SelectedProductType { get; set; }
public List<string> GenderList { get; set; }
public ViewProductModel ViewProductModel { get; set; }
public PostViewShoppingCart ShoppingCart { get; set; }
public string ProductId { get; set; }
public List<PostViewShoppingCart> ShoppingCartList { get; set; }
public bool StockEnquired { get; set; } = false;
我的观点与模型有关 查看
@model myproj.Models.DepartmentProductViewModel
<table class="table table-hover">
<thead>
<tr>
<th>Product</th>
<th>Quantity</th>
<th></th>
<th class="text-center">Price</th>
<th class="text-center">Total</th>
<th> </th>
</tr>
</thead>
<tbody>
@{ int i = 0;}
@foreach (var cartItem in Model.ShoppingCartList)
{
<tr>
<td class="col-sm-8 col-md-6">
<div class="media">
<a class="thumbnail pull-left" href="#">
<img class="media-object" src="@Url.Content(cartItem.ImageURL)?w=72&h=72">
</a>
<div class="media-body">
@Html.HiddenFor(x=>x.ShoppingCartList[i].P_id)
</td>
<td class="col-sm-1 col-md-1" style="text-align: center">
@Html.TextBoxFor(x=>x.ShoppingCartList[i].QtyOrdered)
</td>
}
Ajax Call
function reviewOrder() {
var model = '@Html.Raw(Json.Encode(@Model))';
//alert(modelDataJSON);
$.ajax({
type: 'POST',
url: '/ShoppingCart/ReviewCart/',
data: JSON.stringify(model),
contentType: 'application/json; charset=utf-8',
success: function (data) {
$('#livestockcheck').remove();
$('#activate-step-2').removeClass('hide');
$('#shoppingcartcontents').html(data);
},
error: function (data) {
alert(data);
}
});
控制器
[HttpPost]
public ActionResult ReviewCart([System.Web.Http.FromBody] DepartmentProductViewModel model)
{}
任何建议/帮助
由于