24 Jun 2017

Changing DIV value using jquery Asp.net MVC

Changing DIV value using jquery Asp.net MVC

Guest post 
I have one div division

<div id="myname" name="myname">myvalue</div>

i am changing value of "myvalue" with jquery 
how can i pass myvalue to my controller.

Solution
create a controller get the value by $("#myname").text(); 
and pass it into the controller like this 

for example this is my controller 

[HttpPost]
    public void UpdateTask(TaskModel tmdl)
    {
        sDBSEntities dbOBj = new sDBSEntities();
        Task tObj = dbOBj.Tasks.Single(x => x.ID == tmdl.ID);
        tObj.Name = tmdl.Name;
        tObj.Description = tmdl.Description;
        tObj.DateUpdated = DateTime.Now;
        dbOBj.SaveChanges();
    }


my ajax call would be

var tmdl = {
ID: $("#hdnId").val(),
Name: $("#txtName").val(),
Description: $("#txtDesc").val()
};
$.ajax({
type: 'POST',
url: '/Task/UpdateTask',
data: tmdl,
cache: false,
success: function (result) {
clearAll();
alert("Updated Successfully");
location.reload();
},
error: function () {
alert('Err');
}
});
}


you can post your solution below.

No comments:

Post a Comment