post textboxes values to Controller from View in mvc4

Method 1: 



 Thru  JQUERY

In view :

<div >
    <span>DateTime:</span>
     <input id="txtdatetimepicker" type="text" />
</div>

<div id="dvDescription">
    <span>Description:</span>
    @Html.TextArea("txtDescription")
</div>

<div id="ContentDiv" class="ContentDiv">
</div>

<input type="submit" id="btnStatusAdd" class="addactivitySubmitButton" 
name="Command" value="Save" />

In Jquery:

<script src="~/Scripts/jquery-1.8.2.js">
        $('#btnSave').live("click", function (e) {
             var datetime = $('#txtdatetimepicker').val();
             var des = $('#txtDescription').val();
             var data = {
                                 time: datetime,
                                  descr: des };
        $("#ContentDiv").load('url', data, function () {
         });
      });
<script>


In Controller:

Get Values Using FormCollection


[HttpPost]
 public ActionResult TimeTrackerGrid(FormCollection coll)
 { 
         string description = coll["descr"]; 
         string time = coll["time"]; return View(); 
}

Get Values Using Request.Form

[HttpPost] 
public ActionResult TimeTrackerGrid() 
 { 
        string description = Request.Form["descr"]; 
        string time = Request.Form["time"]; 
        return View(); 
 }

Comments

Popular posts from this blog

How to retain the data annotations or class during modify a table in the database

Interview Questions

AJAX CONTROL