Beginner problem with posting data table to JsonResult
Posted
by ognjenb
on Stack Overflow
See other posts from Stack Overflow
or by ognjenb
Published on 2010-05-20T06:46:22Z
Indexed on
2010/05/20
6:50 UTC
Read the original article
Hit count: 287
asp.net-mvc
|jQuery
With this script I get data from JsonResult (GetDevicesTable) and put them to table ( id="OrderDevices")
<script type="text/javascript">
$(document).ready(function() {
$("#getDevices a").click(function() {
var Id = $(this).attr("rel");
var rowToMove = $(this).closest("tr");
$.post("/ImportXML/GetDevicesTable", { Id: Id }, function(data) {
if (data.success) {
//remove row
rowToMove.fadeOut(function() { $(this).remove() });
//add row to other table
$("#OrderDevices").append("<tr><td>"+ data.DeviceId+ "</td><td>" + data.Id+ "</td><td>" + data.OrderId + "</td></tr>");
} else {
alert(data.ErrorMsg);
}
}, "json");
});
});
<% using (Html.BeginForm()) {%>
<table id="OrderDevices" class="data-table">
<tr>
<th>
DeviceId
</th>
<th>
Id
</th>
<th>
OrderId
</th>
</tr>
</table>
<p>
<input type="submit" value="Submit" />
</p>
<% } %>
When click on Submit I need something like this:
$(document).ready(function() {
$("#submit").click(function() {
var Id = $(this).attr("rel");
var DeviceId = $(this).attr(???);
var OrderId = $(this).attr(???);
var rowToMove = $(this).closest("tr");
$.post("/ImportXML/DevicesActions", { Id: Id, DeviceId:DeviceId, OrderId:OrderId }, function(data) {
}, "json");
});
});
I have problem with this script because do not know how post data to this JsonResult:
public JsonResult DevicesActions(int Id,int DeviceId,int OrderId)
{
orderdevice ord = new orderdevice();
ord.Id = Id;
ord.OrderId = DeviceId;
ord.DeviceId = OrderId;
DBEntities.AddToorderdevice(ord);
DBEntities.SaveChanges();
}
© Stack Overflow or respective owner