Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have one text box where i have shown current date with JS. I have a button below. Now i want to pass the current date on the button click to the controller action method. How could i do that?
Posted
Updated 14-Jun-17 0:11am
v2
Comments
[no name] 22-May-15 1:35am    
What you have tried?
Member 11710169 22-May-15 2:47am    
I have create a text area where i have shown current date by JS, then i put a normal button. now i have create a parameter in my action in the controller. Now my task is on button click the text box current date value will get pass in the action. And in the action i have a sql query, the query will get executed.
[no name] 23-May-15 0:57am    
So Please Keep your text area with in the form as shown in below, If your using button change it as subbmit
@using (Html.BeginForm("Save", "", FormMethod.Post))
{
@Html.TextBox("Date");
<input type="submit" value="save">
}
Member 1021135 17-Jun-17 12:45pm    
ok

 
Share this answer
 
Comments
Member 11710169 22-May-15 2:38am    
The example is good. But i can not use submit button and use form. I need to do it in normal <input type="button">.
Please help.
F-ES Sitecore 22-May-15 3:35am    
Attach a click event to the button that reads the text and makes an ajax call to your action. Google individual aspects if you don't know how to do them ("jquery click event", "jquery read dom element", "jquery ajax"), then put it all together
You can do this on button click call jquery ajax function

<input type="submit" value="Submit" onclick="Send()"></input>


function Send() {
               
                    var url = "/YourController/YourActionResult";
                  
                    $.ajax({
                        url: url,
                        data: { here pass ur textbox value },
                        cache: false,
                        type: "GET"
                    });
                }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900