简体   繁体   中英

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

    }

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"

2 Issues in Code

  1. Never put complete name of controller, you will just need to add prefix ie 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM