a developer's notes – a semi-technical web development BLOG

May 7, 2013

Pass Hidden Input from View to MVC Controller

Filed under: ASP.NET,C# — Duy Nguyen @ 11:51 am
Tags: , , , , ,

Make sure your input has an id AND name attribute. Having just the id attribute will not work.

<% using (Html.BeginForm("MyAction", "Controller", FormMethod.Post, new { id = "formId", target = "_self" })) 
   { %>
     <input type="hidden" name="myHidden" id="myHidden" value="false" />
<% } %>

Then in the controller, access the form values like this.

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult MyAction(FormCollection form)
{
     string myHiddenInput= form["myHidden"];
}
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: