Asp.net MVC - ошибка ввода type = "file" - PullRequest
0 голосов
/ 05 июня 2019

Я создаю форму, содержащую 2 входных текста и 1 входной файл. Когда я выбираю изображение и нажимаю кнопку отправки, возникает ошибка для входного файла

У меня нет подтверждения входного файла!

validation error

это мой код просмотра:

@model Test.Models.Domain.tblCategory
@{
                Layout = null;
}
@using (Html.BeginForm("AddOrEditeCat", "Admin", FormMethod.Post, new {enctype="multipart/form-data",onsubmit="return SubmitCatForm(this)" }))
{
    @Html.AntiForgeryToken()

    @Html.HiddenFor(model => model.id)
    @Html.HiddenFor(model => model.Pic)

    <div class="form-group">
        @Html.Label("Title", new { @class = "control-label" })
        @Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })
        @Html.ValidationMessageFor(model => model.Title)
    </div>

    <div class="form-group">
        @Html.Label("Text", new { @class = "control-label" })
        @Html.EditorFor(model => model.Text, new { htmlAttributes = new { @class = "form-control" } })
    </div>

    <div class="form-group">
    @Html.LabelFor(model=>model.Pic, new { @class = "control-label" })
        <img src="@Url.Content(Model.Pic)" style="margin:10px" height="150" width="150" id="imagePreview" />
        <input type="file" id="ImageUpload" name="ImageUpload" accept="image/jpeg,image/png" onchange="ShowImagePreview(this,document.getElementById('imagePreview'))" />
    </div>

    <div class="form-group">
        <input type="submit" value="Submit" class="btn btn-primary" />
        <input type="reset" value="Reset" class="btn btn-primary btn-danger" />
    </div>

}

а это моя модель:

public partial class tblCategory
{
    public int id { get; set; }
    [Required(ErrorMessage = "*")]
    public string Title { get; set; }
    public string Text { get; set; }
    [DisplayName("Image")]
    public string Pic { get; set; }

    public HttpPostedFileBase ImageUpload { get; set; }

    public tblCategory()
    {
        Pic = "~/Cntent/upload/img/cat/defalt.png";
    }
}
...