views:

227

answers:

2

I am working with ASP.NET MVC application.

I have One master page having one contentplaceholder. I have one view placed in the contentplaceholder of master page. i have few textBoxes say "name", "age" , "email" in it. I also have submit button in my master page.

when i click submit button , postback event will be called in the controller.

//POST
public ActionResult Result(FormCollection Form) { }

Question is if i try to access the value of the text box "name" using Form["name"] it will give me null value.

Instead Form["$ct100$contentplaceholder1$name"] will give me the correct value.

can any one tell how to get the value using only "name" ?

+1  A: 

The input name was autogenerated for you, which you don't want to happen. Try to generate those inputs in MVC-style, like this:

<%=Html.TextBox("name")%>

or like this:

<input type="text" id="name" name="name" value="" />
Palantir
+1  A: 

Don't mix Web Forms with MVC

You shouldn't be using <asp:TextBox id="name" /> but rather

<%= Html.TextBox("name") %>
Robert Koritnik