Renderaction does not consider my validations in ASP.NET models

Asked

Viewed 257 times

0

Renderaction stopped considering the fields marked as [Required] on my models.

Example of one of the models:

private uint IdNews { get; set; }

        [Required(ErrorMessage = "Defina o título.")]
        public string Title { get; set; }

        [UIHint("tinymce_jquery_full"), AllowHtml]
        [Required(ErrorMessage = "Escreva a descrição.")]
        public string Description { get; set; }

        //[RegularExpression(@"^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/\d{4}$", ErrorMessage = "A data é inválida.")]
        [Required(ErrorMessage = "Selecione a data de postagem.")]
        public DateTime PostDate { get; set; }

        [Required(ErrorMessage = "Escreva o nome do Administrador que esta postando.")]
        public Admin AdminName { get; set; }

        public Image Photo { get; set; }

This is the view being loaded with Hrml.Renderaction:

@model BraveryBranded.ASP.Models.News

@{
    ViewBag.Title = "Adicionar";
}

<h2>@ViewBag.Title</h2>

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Nova Notícia</legend>

        <div class="editor-label">
            <h3>*Título</h3>
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Title)
            @Html.ValidationMessageFor(model => model.Title)
        </div>

        <div class="editor-label">
            <h4>Imagem</h4>
        </div>
        <div class="editor-field">
            <input type="file" id="file"/>
        </div>

        <div class="editor-label">
            <h4>*Descrição:</h4>
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Description)
            @Html.ValidationMessageFor(model => model.Description)
        </div>
        <br/>
        <p>
            <button class="btn btn-primary" type="submit">Adicionar</button>
        </p>
    </fieldset>
}

@*<div>
    @Html.ActionLink("Back to List", "Index")
</div>*@

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

View where Renderactions are loaded:

@using BraveryBranded.ASP.Models
@model IEnumerable<BraveryBranded.ASP.Models.News>

@{
    ViewBag.Title = "Notícias";
}

<h2>@ViewBag.Title</h2>

@{
    Html.RenderAction("New", "News");
}
<hr/>
@{
    Html.RenderAction("List", "News");
}
  • Luiz, at the end of your view New has a section for scripts. Copy it whole for the Index. Then we will see the question of the text editor.

  • @Andrecalil did this and has not changed, only the validation fields are working, but the text editor that has not changed anything.

  • The editor works normally on the isolated page?

  • @Andrecalil Sim

  • @Andrecalil One thing I noticed is the size of it, when it opens on the isolated page, it has plenty of space to use the configured size (which is still the default). But I don’t know how to diminish it, I’m a beginner in .net... Does that have to do with?

  • I don’t think so man, what it looks like is that some script is missing for it. When you added Tinymce, did you follow any tutorial? Link here for me to see, please.

  • @Andrecalil It was here: http://www.tugberkugurlu.com/archive/tinymce-html-text-editior-and-asp-net-mvc-setting-it-up-has-become-easy-with-nuget

  • @Andrecalil is giving this error in jquery: Uncaught Typeerror: Object [Object Object] has no method 'tinymce' News:135 (Anonymous Function) News:135 fire jquery-1.10.2.js:3048 self.fireWith jquery-1.10.2.js:3160 jQuery.extend.ready jquery-1.10.2.js:433&#Xa completed;

  • Exactly, some script is missing. I read the tutorial on top but found nothing. You added reference to some script that configured Tiny?

  • @Andrecalil I did not modify anything because it came out working right away, and still works on the page when it is alone. This this strange!

  • @Luiznegrini When you save the model with all blank fields, what happens?

  • @Gypsy.

Show 7 more comments

1 answer

0


The problem was solved using javascript. It was poorly positioned on the page.

But one of the problems still persists!

The Tinymce Text Editor, when used on a page loaded by Render Action does not work, if I load it by the page of New and charge the List with render action Below, it does not open the text editor. If I load it on a page alone, it works face to face. If I load it on your own page using another Render Action also ceases to function.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.