0

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();

    }
1
  • Change <input type="text" id="dp" /> to <input type="text" id="dp" name="Date" /> Commented Sep 17, 2013 at 10:11

2 Answers 2

2

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"

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.