Contents tagged with MVC

  • Manage serialization in .Net Core 2.0

    Hello everybody,

    today I want to write a short notice on how to manage uppercase/lowercase options for serialization in .Net Core.

    In mine practice I often had situation, when javascript or typescript code sends me some staff in lowercase class names, but in C# I'm used to Upper case class names. 

    Another option that you sometime can need is switching between xml and json serialization. How those options can be managed in .Net Core 2.0 ?

    For both of those options ( and even more ) you can use pipeline management of Startup class of ConfigureServices method.

    For example if you need to have xml serialization output you can use following code:

    public class Startup

        {

            // This  … more

  • Subtle difference between Html.TextAreaFor and Html.EditorFor

    Hello everybody,

    today I want to document one gotcha related to difference between Html.TextAreaFor and Html.EditorFor.

    Recently I've had a requirement to add hint text to text fields. In Html world there are two ways to create input field which accepts text: <input type="text" /> and <textarea>some text </textarea>. In MVC world you can create those tags with help of Html.TextAreaFor and Html.EditorFor.

    I've had challenges with trying to apply attribute placeholder to TextAreaFor. EditorFor was pretty simplte to google and find:

    @Html.EditorFor(model => model.YourName, new { htmlAttributes = new { @class = "form-control", placeholder="Your name" } })

    But finally after a research I've … more

  • ASP .Net LifeCycle

    Hello everybody,

    today I want to write few words about ASP .Net lifecycle. 

    Actually just sequence of events. 

    Begin Request

    Resolve request cache

    Map request handler

    Acquire request state

    Request handler execute

    Update request cache

    Log request

    End request

    Here are the 8 main steps of ASP .Net lifecycle. MVC controllers are processed in step 5, RequestHandlerExecute more

  • Trivial implementation of File uploader

    Hello everybody,

    today I want to share with you fragment of code of html extension.

    Imagine that you edit your cshtml file, and see following code:

    @Html.EditorFor(model => model.SomeField

    Then you need to add some file upload and notice, that there is not file upload! 

    How can you fix this situation?

    I propose to use HtmlExtension code. For example like this:

    public static MvcHtmlString FileUpload(this HtmlHelper htmlHelper, string cssClass, object htmlAttrs = null) {

    var tb = new TagBuilder("input");

    tb.MergeAttribute("type", "file");

    tb.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttrs));

    if (!string.IsNullOrWhiteSpace(cssClass)) {

    tb. … more