我发邮件有困难
checkboxes
和
EditorFor
MVC中的值。我有两个班:
public class CompleteReceiving
{
public List<SiteOrderReceiving> order_detail { get; set; } //<- Data from DB. It contains all items for Order Receiving.
public List<SomeClass> new_form { get; set; } //<- Fields for form
}
public class SomeClass
{
[RegularExpression("^[0-9]*$", ErrorMessage = "Receive Quantity can only contain number")]
public decimal? receive_quantity { get; set; }
[RegularExpression("^[0-9]*$", ErrorMessage = "Damaged Quantity can only contain number")]
public decimal? damaged_quantity { get; set; }
public bool IsSelected { get; set; }
}
这是我的观点:
@for(int i = 0; i < Model.order_detail.Count; i++)
{
<tr>
<td>@Html.CheckBoxFor(m => m.new_form[i].IsSelected, new { id = "site_rec_checkbox", @class= "site_rec_checkbox" })
</td>
<td>@Html.EditorFor(m => m.new_form[i].receive_quantity, new { htmlAttributes = new { @class = "form-control fm", @autocomplete = "off", @autofocus = "autofocus", @placeholder = "Receiving Quantity" } })
@Html.ValidationMessageFor(m => m.new_form[i].receive_quantity, "", new { @class = "text-danger" })
</td>
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult SiteOrderReceiving(CompleteReceiving sor)
{
//Code for post
}
问题是每当我选择
checkbox
index
比
1
或
2
这个
List
总是
null
. 但这是我第一次选择
3
或
4
1
或
比它好用多了。
我不知道我做错了什么。
任何帮助都将不胜感激。
更新
这是我的控制器
Action Code
[HttpGet]
public ActionResult SiteOrderReceiving(int? order_id)
{
var get_detail = (from oa in db.order_send
where oa.order_id == order_id
select new SiteOrderReceiving()
{
quantity_send = oa.send_quantity,
date_send = oa.send_date,
order_id = oa.order_id
}).ToList();
var a = new CompleteReceiving();
a.order_detail = get_detail;
return View(a);
}
这是我的
View
@using (Html.BeginForm("SiteOrderReceiving", "Site", FormMethod.Post, new { id = "receive_form" }))
{
@Html.AntiForgeryToken();
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@for(int i = 0; i < Model.order_detail.Count; i++)
{
<tr>
<td>@Html.CheckBoxFor(m => m.new_form[i].IsSelected, new { id = "site_rec_checkbox", @class= "site_rec_checkbox" })
</td>
<td>@Html.EditorFor(m => m.new_form[i].receive_quantity, new { htmlAttributes = new { @class = "form-control fm", @autocomplete = "off", @autofocus = "autofocus", @placeholder = "Receiving Quantity" } })
@Html.ValidationMessageFor(m => m.new_form[i].receive_quantity, "", new { @class = "text-danger" })
</td>
}