---
title: "How to send data from view to controller action in asp.net mvc?"  
description: "How to send data from view to controller action in asp.net mvc?"  
author: "Manoj Bhatt"  
published: 2014-12-09  
updated: 2014-12-10  
canonical: https://www.mindstick.com/forum/12778/how-to-send-data-from-view-to-controller-action-in-asp-dot-net-mvc  
category: "asp.net"  
tags: ["asp.net mvc", "controller"]  
reading_time: 3 minutes  

---

# How to send data from view to controller action in asp.net mvc?

I developed a [custom](https://www.mindstick.com/blog/12298/use-custom-writing-services-to-get-through-the-finals) [HtmlHelper](https://www.mindstick.com/forum/155820/how-to-generate-textbox-control-using-htmlhelper-in-razor-view) [extension method](https://www.mindstick.com/articles/22/extension-method) but that [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) is not [posting](https://www.mindstick.com/forum/34719/cross-page-posting) Action.

## HtmlHelper extension [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp):

```
public static class TestHtmlHelper{    public static MvcHtmlString CreateControl(this HtmlHelper helper, string tagName, IDictionary<string, string> attributes)    {        var newTag = new TagBuilder(tagName);        newTag.MergeAttributes(attributes, true);         return  MvcHtmlString.Create(newTag.ToString(TagRenderMode.Normal));    }     public static string Image(this HtmlHelper helper, string id, string url, string alternateText, object htmlAttributes)    {        // Create tag builder        var builder = new TagBuilder("img");         // Create valid id        builder.GenerateId(id);         // Add attributes        builder.MergeAttribute("src", url);        builder.MergeAttribute("alt", alternateText);        builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));         // Render tag        return builder.ToString(TagRenderMode.Normal);    } }
```

**//[View](https://yourviews.mindstick.com/view/84701/layoffs-in-google-india-2023-view) code**

```
 @using (Html.BeginForm("Go","Home",FormMethod.Post)){    IDictionary<string, string> d = new Dictionary<string, string>();    d.Add("type", "text");    d.Add("id", "text1");    d.Add("required", "required");    @Html.Raw(Html.CreateControl("input", d))    @Html.Raw(Html.Image("image1", "/Images/bullet.png", "bullet", new { border = "4px" }))    d = null;    d = new Dictionary<string, string>();    d.Add("type", "submit");    d.Add("value", "Go");    @Html.Raw(Html.CreateControl("input", d))    <span></span>    d = null;    d = new Dictionary<string, string>();    d.Add("value", "text");    d.Add("id", "span1");    d.Add("text", "required");    @Html.Raw(Html.CreateControl("span", d))}
```

**// [Controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc) code**

```
public ActionResult Index(){    ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";     return View();}[HttpPost]public ActionResult Go(string test){    return Content(test);}
```

I didn't get data in [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) test. Please help me for that.... I want to submit that data to DB.

## Replies

### Reply by Anonymous User

Put your inputs inside a form tag. All the input data will be sent to the controller on form submit. Please see the example:

## View:

```
@using (Html.BeginForm("Search","Events")){  
@Html.TextBox("name")   <input type="submit" value="Search" />}
```

## Controller:

```
public class EventsController: Controller{   public ActionResult Search(string name)   {      //some operations goes here       return View();
//return some view to the user   }}
```

If you need to work with more complex types just lern how to use models in ASP.NET MVC. Here is short example:

## Razor:

```
@model UserModel @using (Html.BeginForm("Search", "Events")){   @Html.TextBoxFor(m => m.FirstName)   @Html.TextBoxFor(m => m.LastName)   <input type="submit" value="Search" />}
```

## Controller:

```
public class EventsController: Controller{   public ActionResult Search(UserModel model)   {      //some operations goes here       return View(); //return some view to the user   }}
```

## Model (C#):

```
public class UserModel{   public string FirstName { get; set; }   public string LastName { get; set; }}
```

### Reply by Anonymous User

To get input values as parameters for an MVC action, you need to include NAME for the input types.

I do not see NAME for any input types in your code.

Also I do not see TEST in your code

## For example, if your form is -

```
@using (Html.BeginForm("Submit","Ajax",FormMethod.Post)){    <input type="text" name="Rami"/>    <input type="submit" value="Go"/>}
```


---

Original Source: https://www.mindstick.com/forum/12778/how-to-send-data-from-view-to-controller-action-in-asp-dot-net-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
