ModelState.IsValid和图像

时间:2019-07-02 14:30:38

标签: c# asp.net-mvc

当打开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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>

0 个答案:

没有答案
相关问题