Showing posts with label submit button in html helper class. Show all posts
Showing posts with label submit button in html helper class. Show all posts

Friday, 22 November 2013

HTML Helper class in Razor View Engine

HTML Helper class in Razor View Engine
(BeginForm,Label,Texbox,Submit button)

In MVC, many helper methods are added to create HTML control perfectly. As in Web Application we use control class to create control in asp.net, here we use HTML helper classes. But these methods are very light weight as they not maintain any viewstate and return as string.

Methods in HTML Helper Classes:-

Begin Form

As in HTML we use Form method in which we assign action, method etc here we use BeginForm to implement this task.

Syntax for Begin Form:-

@using (Html.BeginForm("Index", "Home", FormMethod.Post))
    {
   
       
   
    }

In this method index is an action name, home is a controller name and formMethod Enum is used to set method which we already discussed in my previous article. We add all control in this opening and closing braces.

Label

Label is used to show data on screen

Syntax of Label

@Html.Label("Enter your First Name")

It will simply create a label which shows the message

Textbox

Textbox method is used to create a textbox in screen. We pass id and name as string to this method.

For example:-

@Html.TextBox("fname")
In this method fname is worked as id and name for this control.