Contents tagged with MVC

  • 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