PDA

View Full Version : [CLOSED] [MVC] Get values from HttpPost methodes



UnifyEducation
Jul 06, 2012, 1:04 PM
Hi,

I have the same question as http://forums.ext.net/showthread.php?18269-Razor-Bind-and-get-values-from-textfied-in-httppost-method-of-controller

But your answers in that post is not very clear.
Can you give me a example showing how to get values from the Views in the Controllers through HttpPost methode?

Thank you

Daniil
Jul 06, 2012, 2:37 PM
Hi,

Do you need to use a common HTML <form> or a <ext:FormPanel> control?

UnifyEducation
Jul 06, 2012, 2:58 PM
Hi,

Do you need to use a common HTML <form> or a <ext:FormPanel> control?

If possible, can you use Ext FormPanel with Razor. :)

Daniil
Jul 06, 2012, 3:12 PM
Here you are.

Example View

<!DOCTYPE html>

<html>
<head>
<title>Ext.Net.MVC v2 Example</title>
</head>
<body>
@Html.X().ResourceManager()

@(Html.X().FormPanel()
.Url("/Razor/Submit")
.Width(300)
.Items(items =>
{
items.Add(Html.X().TextField().ID("TextField1").Text("Value 1"));
items.Add(Html.X().TextField().ID("TextField2").Text("Value 2"));
}
)
.Buttons(buttons =>
buttons.Add(Html.X().Button()
.Text("Submit")
.Listeners(ls =>
ls.Click.Handler = @"this.up('form').submit({
success : function (form, action) {
eval(action.result.script);
}
});"
)
)
)
)
</body>
</html>



Example Controller Action

public ActionResult Submit(FormCollection values)
{
FormPanelResult r = new FormPanelResult();
r.Script = string.Format("alert('{0} {1}')", values["TextField1"], values["TextField2"]);

return r;
}