Я не могу загрузить свое изображение, когда ModelState.IsValid включен.Есть ли определенный способ, которым я должен писать код в моем контроллере, я снял его, и это код, который работает, но не возвращает мои данные проверки.Я добавил представленный ниже код для получения дополнительной информации благодаря
[Route("Create")]
[HttpPost]
public ActionResult Create(ContentViewModel model)
{
HttpPostedFileBase file = Request.Files["ImageData"];
ContentRepository service = new ContentRepository();
int i = service.UploadImageInDataBase(file, model);
if (i == 1)
{
return RedirectToAction("Submitted");
}
return View(model);
}
Просмотреть код
@using (Html.BeginForm("Create", "Content", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<div>
</div>
<br>
<div class="card bg-light mb-3">
<div class="card-header bg-primary text-white">
<h2 class="text-center">Quality & Innovation HUB Members and Clinician Project Submission e-Form</h2>
<p class="one"></p>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-3">
<label for="x_QIHubProjectTemplate_FullName" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">1</span> Full Name</label>
@*@Html.TextBoxFor(x => x.FullName, new { @Value = "Michelle Mabbs", style = "width: 200px;" })*@
@Html.TextBoxFor(x => x.FullName, null, new { @class = "form-control" })
@Html.ValidationMessageFor(x => x.FullName)
</div>
<div class="col-md-3">
<label for="x_QIHubProjectTemplate_StaffGroup" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">2</span> Staff Group</label>
@* @Html.TextBoxFor(x => x.StaffGroup, new { @Value = "Add Prof Scientific and Technic", style = "width: 200px;" })*@
@Html.DropDownListFor(x => x.StaffGroup, Model.StaffGroupSel, new
{
@id = "Content_JobStaffGroup",
@class = "form-control",
onchange = "return ChangeDropDownStaffGroup()"
,
@required = "true"
})
</div>
<div class="col-md-3">
<label for="x_QIHubProjectTemplate_Position" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">3</span> Job Title</label>
@* @Html.TextBoxFor(x => x.Position, new { @Value = "Advanced Practitioner", style = "width: 200px;" })*@
@Html.DropDownListFor(x => x.Position, new SelectList(
new List<Object>{
new { value = "" , text = "" },
},
"value",
"text", ""
), new { @class = "form-control", id = "Content_JobTitle", onchange = "", @required = "true" })
</div>
<div class="col-md-3">
<label for="x_QIHubProjectTemplate_Skill" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">4</span> Quality & Improvement skills </label>
@Html.TextBoxFor(x => x.Skills, htmlAttributes: new { id = "myAutocomplete", type = "text", @class = "form-control" })
</div>
</div>
<br>
<div class="row">
<div class="col-md-3">
<label for="x_QIHubProjectTemplate_EmailID" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">5</span> Email Address</label>
@Html.TextBoxFor(x => x.EmailID, null, new { @class = "form-control" })
</div>
<div class="col-md-3">
<label for="x_QIHubProjectTemplate_Contact" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">6</span> Telephone Number</label>
@Html.TextBoxFor(x => x.ContactNo, null, new { @class = "form-control" })
</div>
<div class="col-md-3">
<label for="x_QIHubProjectTemplate_Department" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">7</span> Area</label>
@* @Html.TextBoxFor(x => x.Area, new { @Value = "Cent", style = "width: 200px;" })*@
@Html.DropDownListFor(x => x.Area, Model.AreaGroupSel, new
{
@id = "Content_Area",
@class = "form-control",
onchange = "return ChangeDropDownArea()"
,
@required = "true"
})
</div>
<div class="col-md-3">
<label for="x_QIHubProjectTemplate_HospitalSite" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">8</span> Hospital Site</label>
@* @Html.TextBoxFor(x => x.HospitalSite, new { @Value = "Abergele", style = "width: 200px;" })*@
@Html.DropDownListFor(x => x.HospitalSite, new SelectList(
new List<Object>{
new { value = "" , text = "" },
},
"value",
"text", ""
), new { @class = "form-control", id = "Content_Hospital", onchange = "", @required = "true" })
</div>
</div>
<br />
<div class="row">
<div class="col-md-6">
<label for="x_QIHubProjectTemplate_ContactMe" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">9</span> Are you happy to contacted by other QI members:</label>
</div>
<div class="radio icheck-primary col-md-1">
@Html.RadioButtonFor(x => x.ContactMe, "Yes", new { @checked = "checked", id = "x_ContactMe_Y", @onclick = "return hidePatientPanel()" })
<label for="x_ContactMe_Y">Yes</label>
</div>
<div class="radio icheck-primary col-md-1">
@Html.RadioButtonFor(x => x.ContactMe, "No", new { id = "x_ContactMe_N", @onclick = "return hidePatientPanel()" })
<label for="x_ContactMe_N">No</label>
</div>
</div>
</div>
</div>
<div class="card bg-light mb-3">
<div class="card-body">
<div class="row">
<div class="col-md-6">
<label for="x_QIHubProjectTemplate_AreaOfInterest" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">10</span> Please select your main Area of Interest:</label>
</div>
<div class="radio icheck-primary col-md-1">
@Html.RadioButtonFor(x => x.AreaOfInterest, "Specialty", new { @checked = "checked", id = "x_AreaOfInterestSpecialty_S", @onclick = "return hidePatientPanel()" })
<label for="x_AreaOfInterestSpecialty_S">Specialty</label>
</div>
<div class="radio icheck-primary col-md-1">
@Html.RadioButtonFor(x => x.AreaOfInterest, "Topic", new { id = "x_AreaOfInterestSpecialty_T", @onclick = "return hidePatientPanel()" })
<label for="x_AreaOfInterestSpecialty_T">Topic</label>
</div>
<div class="radio icheck-primary col-md-1">
@Html.RadioButtonFor(x => x.AreaOfInterest, "Other", new { id = "x_AreaOfInterestSpecialty_O", @onclick = "return showPatientPanel()" })
<label for="x_AreaOfInterestSpecialty_O">Other</label>
</div>
</div>
<div class="row">
<div class="icheck-primary col-md-4 ">
@Html.TextBox("f", new { @class = "form-control", @style = "pull-right" })
</div>
<div class="icheck-primary col-md-4 ">
@Html.TextBox("g", new { @class = "form-control", @style = "pull-right" })
</div>
<div class="icheck-primary col-md-4 ">
<div id="patientPanel">
@Html.TextBoxFor(x => x.AreaOfInterestOther, null, new { @class = "form-control", @style = "pull-right" })
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label for="x_QIHubProjectTemplate_QINetworks" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">11</span> Please select QI networks you are a member of:</label>
</div>
<div class="radio icheck-primary col-md-1">
@Html.RadioButtonFor(x => x.Membership, "Bevan", new { @checked = "checked", id = "x_Membership_B", @onclick = "return hidePatientPanelA()" })
<label for="x_Membership_B">Bevan</label>
</div>
<div class="radio icheck-primary col-md-1">
@Html.RadioButtonFor(x => x.Membership, "Q", new { id = "x_Membership_M", @onclick = "return hidePatientPanelA()" })
<label for="x_Membership_M">Q</label>
</div>
<div class="radio icheck-primary col-md-1">
@Html.RadioButtonFor(x => x.Membership, "Other", new { id = "x_Membership_O", @onclick = "return showPatientPanelA()" })
<label for="x_Membership_O">Other</label>
</div>
</div>
<div class="row">
<div class="icheck-primary col-md-4 ">
@Html.TextBox("f", new { @class = "form-control", @style = "pull-right" })
</div>
<div class="icheck-primary col-md-4 ">
@Html.TextBox("g", new { @class = "form-control", @style = "pull-right" })
</div>
<div class="icheck-primary col-md-4 ">
<div id="patientPanelA">
@Html.TextBoxFor(x => x.MembershipOther, null, new { @class = "form-control", @style = "pull-right" })
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label for="x_QIHubProjectTemplate_QITraining" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">12</span> Please select relevant QI training you have undertaken:</label>
</div>
<div class="radio icheck-primary col-md-1">
@Html.RadioButtonFor(x => x.QITraining, "IA", new { @checked = "checked", id = "x_QITraining_IA", @onclick = "return hidePatientPanelB()" })
<label for="x_QITraining_IA">IA</label>
</div>
<div class="radio icheck-primary col-md-1">
@Html.RadioButtonFor(x => x.QITraining, "IQT", new { id = "x_QITraining_IQT", @onclick = "return hidePatientPanelB()" })
<label for="x_QITraining_IQT">IQT's</label>
</div>
<div class="radio icheck-primary col-md-1">
@Html.RadioButtonFor(x => x.QITraining, "Other", new { id = "x_QITraining_O", @onclick = "return showPatientPanelB()" })
<label for="x_QITraining_O">Other</label>
</div>
</div>
<div class="row">
<div class="icheck-primary col-md-4 ">
@Html.TextBox("f", new { @class = "form-control", @style = "pull-right" })
</div>
<div class="icheck-primary col-md-4 ">
@Html.TextBox("g", new { @class = "form-control", @style = "pull-right" })
</div>
<div class="icheck-primary col-md-4 ">
<div id="patientPanelB">
@Html.TextBoxFor(x => x.QITrainingOther, null, new { @class = "form-control", @style = "pull-right" })
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label for="x_QIHubProjectTemplate_ProjectCategory" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">13</span> Please select a project category:</label>
</div>
@Html.DropDownListFor(x => x.ProjectCategory, Model.ProjectGroupSel, new
{
@id = "",
@class = "form-control",
onchange = ""
,
@required = "true"
})
</div>
<br>
<div class="row">
<div class="col-md-6">
<label for="x_QIHubProjectTemplate_Title" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">14</span> Please provide a title for your project:</label>
</div>
@Html.TextBoxFor(x => x.Title, null, new { @class = "form-control" })
</div>
<br>
<div class="row">
<div class="col-md-6">
<label for="x_QIHubProjectTemplate_Description" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">15</span> Please provide a description for your project:</label>
</div>
@*<div style="overflow: auto; height: 200px; width: 250px;">
<asp:TextBox textmode="multiline" runat="server" ID="PedEva" name="PedEva" class="div_handelingsplan" style="OVERFLOW:auto; width:380px; height:100px;"></asp:TextBox>
</div>*@
@Html.TextAreaFor(x => x.Description, 1,40, new { style = " overflow: visible;" ,@class = "form-control" })
</div>
<br>
<div class="row">
<div class="col-md-6">
<label for="x_QIHubProjectTemplate_Aims" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">16</span> Please provide details of the aim of your project:</label>
</div>
@Html.TextBoxFor(x => x.Aims, null, new { @class = "form-control" })
</div>
</div>
</div>
<div class="card bg-light mb-3">
<div class="card-body">
<div class="row">
<div class="col-md-6">
<label for="x_QIHubProjectTemplate_ProjectCompleted" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">17</span> Is your project completed?</label>
</div>
<div class="radio icheck-primary col-md-1">
@Html.RadioButtonFor(x => x.Stage, "Completed", new { @checked = "checked", id = "x_ProjectCompleted_Y", @onclick = "return showPatientPanel()" })
<label for="x_ProjectCompleted_Y">Yes</label>
</div>
<div class="radio icheck-primary col-md-1">
@Html.RadioButtonFor(x => x.Stage, "Incomplete", new { id = "x_ProjectCompleted_N", @onclick = "return hidePatientPanel()" })
<label for="x_ProjectCompleted_N">No</label>
</div>
</div>
<br>
<div class="row">
<div class="col-md-6">
<label for="x_QIHubProjectTemplate_CompletitionDate" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">18</span> Please provide a completion date for your project:</label>
</div>
@Html.TextBoxFor(x => x.CompletitionDate, new { @class = "form-control datepicker" })
</div>
<br>
<div class="row">
<div class="col-md-6">
<label for="x_QIHubProjectTemplate_KeyWord1" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">19</span> Please insert up to 3 keywords for your project:</label>
</div>
@Html.TextBoxFor(x => x.KeyWord1, htmlAttributes: new { id = "myAutocomplete", type = "text", @class = "form-control" })
</div>
<br>
<div class="row">
<div class="col-md-6">
<label for="x_QIHubProjectTemplate_KeyWord2" class="control-label jmLabelUnbold medium"><span class="badge badge-pill badge-primary">20</span> Please upload your project:</label>
</div>
<input type="file" name="ImageData" id="ImageData" onchange="fileCheck(this);" />
@Html.ValidationMessageFor(x => x.Image)
</div>
<br>
<input type="submit" value="Upload Project" class="btn btn-primary" />
</div>
</div>
}
</div>