Avatar billede tinaw25 Nybegynder
04. maj 2016 - 21:29

Validation på et partial view

Hej

Jeg har et partial view, hvor jeg har en form. Men når jeg trykker på submit knappen og der er ikke er noget i felterne, bliver error beskederne ikke vist.

Jeg har brugt flere timer på at søge efter en brugbar løsning uden held.
Jeg fandt en løsning hvor jeg bruger ajax, men her skulle jeg ændre typen på knappen fra en submit til en button type, hvilket gør at jeg ikke kan få fileupload til at virke.

Jeg håber virkelig at der er nogle der kan hjælpe mig med problemet, har virkelig brugt mange timer på google uden det store held :-(.

Mit partial view kode :

  @using (Html.BeginForm("GetPartialView", "Manage", FormMethod.Post, new { enctype="multipart/form-data", id = "LoginForm" }))
    {
        @Html.AntiForgeryToken()
   

          <div class="col-md-8 col-sm-10">
                <div class="reg-page">
                    <div class="reg-header">
                        <h2><i class="fa fa-pencil"></i> Opret annonce</h2>
                        <p>På denne side har du mulighed for at ændre dine profil data, samt at slette din profil</p>
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model => model.Isbn)
                        @Html.EditorFor(model => model.Isbn, new { htmlAttributes = new { @class = "form-control" } })
                        <p style="font-size:14px;">f.eks 978-1-491-90086-4</p>
                        @Html.ValidationMessageFor(model => model.Isbn, "", new { @class = "text-danger" })
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model => model.TitleEdition)
                        @Html.EditorFor(model => model.TitleEdition, new { htmlAttributes = new { @class = "form-control" } })
                        <p style="font-size:14px;">f.eks Visual C# 2012 Programmering Udgave 2</p>
                        @Html.ValidationMessageFor(model => model.TitleEdition, "", new { @class = "text-danger" })
                    </div>
                    <div class="form-group">
                        @Html.LabelFor(model => model.Author)
                        @Html.EditorFor(model => model.Author, new { htmlAttributes = new { @class = "form-control" } })
                        <p style="font-size:14px;">f.eks Karli Watson, Jacob Vibe Hammer..osv</p>
                        @Html.ValidationMessageFor(model => model.Author, "", new { @class = "text-danger" })
                    </div>
                    <div class="form-group">
                        @Html.LabelFor(model => model.ShippingPrice)
                        @Html.EditorFor(model => model.ShippingPrice, new { htmlAttributes = new { @class = "form-control" } })
                        <p style="font-size:14px;">f.eks 70</p>
                        @Html.ValidationMessageFor(model => model.ShippingPrice, "", new { @class = "text-danger" })
                    </div>
                    <div class="form-group">
                        @Html.LabelFor(model => model.Price)
                        @Html.EditorFor(model => model.Price, new { htmlAttributes = new { @class = "form-control" } })
                        <p style="font-size:14px;">f.eks 200</p>
                        @Html.ValidationMessageFor(model => model.Price, "", new { @class = "text-danger" })
                    </div>
                    <div class="form-group">
                        @Html.LabelFor(model => model.Collected)
                        <div class="input-group">
                            <span class="input-group-addon">
                                @Html.CheckBoxFor(model => model.Collected, new { id = "checkbox" })
                            </span>

                            <div id="isChecked">
                                @Html.EditorFor(model => model.ZipCode, new { htmlAttributes = new { @class = "form-control", @disabled = "disabled" } })
                            </div>


                        </div>
                        <p style="font-size:14px;">f.eks Hvis bog kan afhentes, skriv post nr.</p>
                    </div>
                    <div class="form-group">
                        @Html.LabelFor(model => model.Information)
                        @Html.TextAreaFor(model => model.Information, new { @class = "form-control", @cols = 80, @rows = 5 })
                        <p style="font-size:14px;">f.eks Uddybende informationer</p>
                    </div>
                    <div class="form-group">
                      @Html.LabelFor(model => model.ImageFile)
                     
                            <!-- Example file element -->
                            <input type="file" name="FileUpload1" id="FileUpload1" />
                   
                    </div>
                    <div class="form-group">
                        @Html.LabelFor(model => model.BookCondition)
                        <div class="radio">
                            <label>
                                @Html.RadioButtonFor(model => model.BookCondition, "Ny & Fejlfri", new { @checked = false }) Ny & Fejlfri
                            </label>
                            <br />
                            <label>
                                @Html.RadioButtonFor(model => model.BookCondition, "Næsten brugt", new { @checked = false }) Næsten brugt

                            </label>
                            <br />
                            <label>
                                @Html.RadioButtonFor(model => model.BookCondition, "Brugt, men ikke slidt", new { @checked = false }) Brugt, men ikke slidt
                            </label>
                            <br />
                            <label>
                                @Html.RadioButtonFor(model => model.BookCondition, "Lidt slidt", new { @checked = false }) Lidt slidt
                            </label>
                            <br />
                            <label>
                                @Html.RadioButtonFor(model => model.BookCondition, "Meget slidt", new { @checked = false }) Meget slidt
                            </label>
                        </div>
                    </div>

                    <hr>
                    <div class="row">
                        <div class="col-lg-6 checkbox">
                        </div>
                        <div class="col-lg-6 text-right">
                            <button id="loginButton" class="btn btn-common-small" type="button">Opret</button>
                        </div>

                    </div>

                </div>

            </div>
   

    }
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester