Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sean 141 posts 179 karma points
    Apr 12, 2012 @ 12:44
    Sean
    0

    Custom html helpers how to?

    Hi There,

    How can I create custom HTML helpers in umbraco v5? I'd like to take advantage of the new HTML 5 input types.

    Has anyone been able to get this to work? If so can you post your solution.

    Thanks in advance

    !-- as per this tutorial (http://shazwazza.com/post/Umbraco-v5-Surface-Controller-Forms.aspx#id_1bb23912-f054-4796-912a-07ef5be9c55e) this works but the form and code is generated. 

    @inherits RenderViewPage

    @using Umbraco.Cms.Web;

    @using mynamespace.Models;

     

    @{ var someModel  = new mynamespace.Models.myModel(); }

     

     

     

    @using(Html.BeginUmbracoForm("HandleFormSubmit", "SurfaceForm"))

    {

        @Html.ValidationSummary(prefix: "SurfaceForm")

        @Html.EditorFor(x => someModel, "", "SurfaceForm")

        <input type="submit"/>

    }

     

    !-- I also tried this method and had a little success but to validate I had to use the form collection rather than the model.

     

    @inherits RenderViewPage

    @using Umbraco.Cms.Web;

    @using mynamespace.Models;

     

    @{ var someModel = new mynamespace.Models.myModel();}

     

    @using(Html.BeginUmbracoForm("HandleFormSubmit", "MySurface"))

    {

     

    <fieldset>

    <legend>Contact me</legend>

    <ul>

    <li>

    @Html.LabelFor(model => someModel.Name): 

    @Html.EditorFor(x => someModel.Name, new {type="text", @class = "testModel", @maxlength = "250", @placeholder="Please enter your name"})

    @Html.ValidationMessageFor(m => someModel.Name)

    </li>

    <li>

    @Html.LabelFor(model => someModel.Phone): @Html.EditorFor(x => someModel.Phone, new {type="number", @class = "testModel", @maxlength = "250"})

    </li>

    <li>

     @Html.LabelFor(model => someModel.Email): @Html.EditorFor(x => someModel.Email, new {type="email", @class = "testModel", @maxlength = "250", @placeholder="Please enter your email"})

     @Html.ValidationMessageFor(x => someModel.Email)

     </li>

     <li>

              <input type="submit" value="Submit" />

              </li>

    </ul>

    </fieldset>

    }

     

Please Sign in or register to post replies

Write your reply to:

Draft