SyntaxHighlighter

Monday, December 15, 2014

Part II - My Editor Template for String DataType

My DataType Editor Template

NOTES : This is continuation of my first article on My Editor Template for Input Form 

My Objective

In order to use the InputTemplate, I also need to create my own template for the String, Single and Int32 datatype.

This requirement is to enable implementation of CSS styling on the textbox.

@Html.Editor(prop.PropertyName, new { @class = "text-box single-line form-control" }

For dropdown list, I can apply CSS styling simply by this call

@Html.DropDownList(prop.PropertyName,(IEnumerable<SelectListItem>) ViewData[prop.PropertyName], new { @class = "form-control" }) 


My Template

The template file is a partial view and created under folder \View\Shared\EditorTemplates\

String.cshtml

@model string
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, ViewData) 

Single.cshtml

@model Single?
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, ViewData)


Int32.cshtml

@model Int32?
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, ViewData) 


No comments:

Post a Comment