PDA

View Full Version : [Razor] Bind and get values from textfied in httppost method of controller



vs.mukesh
Apr 06, 2012, 3:13 PM
Hi,

Below i mentioned simple MVC 3 example page which is created by Pure HTML elements.


ViewPage1.cshtml




@model Merrill.Mll.Domain.AuthenticationToken
@using (Html.BeginForm())
{
<div>
@Html.TextBoxFor(model => model.LoginId, new { tabindex = 1, style = "font-size:16px; width:210px" })
</div>
<div>
@Html.TextBoxFor(model => model.Password, new { tabindex = 2, @type = "password", style = "font-size:16px; width:210px" })
</div>
<div>
<input type="submit" value="Login" />
</div>
}




LoginController.cs



public ActionResult ViewPage1()
{
return View();
}
[HttpPost]
public ActionResult ViewPage1(AuthenticationToken model)
{
return View();
}


My objective is i have to achieve the same with EXT.NEt 2.0 controls (Razor view)
like


@Html.X().TextField().ID("email").Vtype("email").Width(210).EmptyText("Enter your E-mail address").MsgTarget(Ext.Net.MessageTarget.Side).AllowBlank (false).BlankText("E-mail is required")
@Html.X().TextField().ID("passwordfield").InputType(Ext.Net.InputType.Password).Width(210) .MsgTarget(Ext.Net.MessageTarget.Side).AllowBlank( false).BlankText("Password is required")


In that i have below mentioed queries.

1. In which property i have to bind my model values.
2. How to get those values in my controller Post method.

If it possible means give me some code samples.

Thanks in advance.

Regards,
Mukesh Selvaraj

Daniil
Apr 09, 2012, 2:07 PM
Hi,


1. In which property i have to bind my model values.

At the moment it's possible via manual binding only:

@Html.X().TextField().Text(Model.ModelProperty)


2. How to get those values in my controller Post method.

As usual, from Request or setting up a parameter:

MyAction(string textfieldname)
or from FormCollection

MyAction(FormCollection values)