我想创建Invoice Create View。我的视图模型如下:
public class InvoiceCreate
{
public IEnumerable<InvoiceItem> InvoiceItems { get; set; }
public IEnumerable<Recipient> Recipients { get; set; }
public Sender Sender { get; set; }
public Invoice Invoice { get; set; }
public string name { get; set; }
}
获取方法如下:
public ActionResult Create()
{
InvoiceCreate invoice = new InvoiceCreate();
invoice.InvoiceItems = (new Invoice.Model.InvoiceItem[20]).AsQueryable();
invoice.Recipients = (new Recipient[20]).AsQueryable();
invoice.Sender = new Sender() { Adrress="O.Karimov"};
invoice.Invoice = new Invoice.Model.Invoice();
return View(invoice);
}
我的看法如下:
@using (Html.BeginForm(new { id = "submitForm" }))
{
@Html.ValidationSummary(true)
@Html.TextBoxFor(model => model.name);
<div>
<div id="head">
<h1>Invoice</h1>
<div>
@Html.TextBoxFor(model => model.Invoice.InvoiceNumber, new { placeholder = "Invoice number" })
</div>... @for (var itemIndex = 1; itemIndex < Model.Recipients.Count(); itemIndex++)
{
<div class="recipient-row unvisible">
<button type="button" class="close" data-dismiss="alert" style="float: left; margin: 6px;">×</button>
@Html.TextBoxFor(model => model.Recipients.ElementAt(itemIndex).CustomerName, new { placeholder = "Contact name" })
@Html.TextBoxFor(model => model.Recipients.ElementAt(itemIndex).Email, new { type = "email", placeholder = "example@mail.ru" })
</div>
}
<div class="input-append date" data-form="datepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
@Html.TextBoxFor(model => model.Invoice.InvoiceDate, new { placeholder = "Invoice date", @Value = System.DateTime.Now.ToShortDateString(), @class = "grd-white", data_form = "datepicker" })
</div>
</div> <button type="submit" id="btnSave" name="Command" value="Save" class="btn btn-primary">Save</button>
<button type="submit" id="btnSubmit" name="Command" value="SaveDraft" class="btn btn-info">Save as draft</button>
<button type="submit" id="btnCancel" name="Command" value="Cancel" onclick="$('#submitForm').submit()" class="btn btn-danger">Cancel</button>
<input type="submit" name="name" value=" " />
</div>
}
邮寄方式如下:
[HttpPost]
public ActionResult Create(InvoiceCreate invoice, string Command)
{
switch (Command)
{
case "Save":
{
}
break;
case "SaveDraft":
{
}
break;
default:
return RedirectToActionPermanent("Index");
}
return RedirectToActionPermanent("Index");
}
我的问题是,当我单击 Post 方法中视图中的任何按钮时,发票变量为空。我该如何解决?提前致谢。