Inkey
Inkey

Reputation: 2207

ASP.NET MVC from view to controller

I am new to asp.net MVC and i am wondering how i would go about passing a date from a Jquery DateTime picker and pass it across to the controller then do some linq and return the new value to the page.

I have had a play around with @Html.BeginForm but with no joy.

ViewCode

 @Html.BeginForm("GetSigmaDateInfo", "HomeController", FormMethod.Post)
{
        <h3>Date :</h3>   <input type="text" id="dp" />
       <input type="submit" value="Update" />
       }

On the button click above i would like to retrieve data from a linq statement and return it to the page.

Controller Code

 [HttpPost]
    public ActionResult GetSigmaDateInfo(string Date)
    {
        string test = null;
        return View();

    }

Upvotes: 0

Views: 108

Answers (2)

Nipun Ambastha
Nipun Ambastha

Reputation: 2573

2 Issues in Code

  1. Never put complete name of controller, you will just need to add prefix i.e. Home
  2. Name of the elements have to be same name of the parameters that is being passed in controller

And as you are new to MVC, please read this article http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx

It gives everything you want and tells everything

Upvotes: 2

alaasdk
alaasdk

Reputation: 1998

the textbox should have the same name as the parameter.. like below

public ActionResult GetSigmaDateInfo(string dp)

&

<input type="text" id="dp" name="dp" />

-

also, remove "controller" keyword from the form definition "Home" instead of "HomeController"

Upvotes: 2

Related Questions