我想在Kendo网格中使用输入文件,将数据和文件发布到控制器。 但是IFormFile为null,我无法保存文件。
我的模特。
public class LeadAttachmentViewModel
{
public int LeadAttachmentId { get; set; }
public IFormFile AttachTypeUrl { get; set; }
public int AttachTypeId { get; set; }
public Guid UniqueFileIdentifier { get; set; }
public string MetaData { get; set; }
}
我的观点
<div class="k-rtl">
@(Html.Kendo().Grid<MkProject.Models.ViewModel.LeadAttachmentViewModel>
()
.Name("gridLeadAttachment")
.Columns(columns =>
{
columns.ForeignKey(e => e.AttachTypeId, (SelectList)ViewData["AttachTypeList"]).EditorTemplateName("GridForeignKey").Title("نوع فایل").Width("70px");
columns.Bound(c => c.MetaData).Title("توضیحات").Width(190);
columns.Bound(e => e.AttachTypeUrl).EditorTemplateName("FileUpload1").Title("فایل").ClientTemplate("#:UniqueFileIdentifier#");
columns.Command(cmd => { cmd.Edit().Text("ویرایش"); cmd.Destroy().Text("حذف"); }).Title("ابزار");
})
.ToolBar(tb => { tb.Create().Text("ایجاد "); tb.Excel().Text("خروجی در اکسل"); tb.Pdf().Text("خروجی در PDF"); })
.Editable(ed => ed.Mode(GridEditMode.InLine))
.HtmlAttributes(new { style = "height: 400px;" })
.Scrollable()
.Groupable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(6))
.DataSource(dataSource => dataSource
.Ajax()
.Model(md =>
{
md.Id(m => m.LeadAttachmentId);
// md.Field(p => p.AgentId);
//.DefaultValue(
//ViewData["AgentId"] as MkProject.Models.Agent);
})
.Read(read => read.Action("LeadAttachment_Read", "Leads"))
.Create(cr => cr.Action("LeadAttachment_Create", "Leads"))
.Update(up => up.Action("LeadAttachment_Update", "Leads"))
.Destroy(de => de.Action("LeadAttachment_Delete", "Leads")))
.Excel(excel => excel
.FileName("Leads.xlsx")
.Filterable(true)
.ProxyURL(Url.Action("Excel_Export_Save", "Grid"))
)
.Pdf(pdf => pdf
.AllPages()
.AvoidLinks()
.PaperSize("A4")
.Scale(0.8)
.Margin("2cm", "1cm", "1cm", "1cm")
.Landscape()
.RepeatHeaders()
.TemplateId("page-template")
.FileName("Kendo UI Grid Export.pdf")
.ProxyURL(Url.Action("Pdf_Export_Save", "Grid"))
)
.Filterable()
)
</div>
file upload template
@model string
@Html.HiddenFor(m => m)
@Html.ValidationMessageFor(m => m)
@Html.TextBoxFor(model => model, new { @class = "k-textbox", type = "file", name = Model, formenctype = "multipart/form-data" })