Hi,
Please help
Can we send data from View to controller without clicking a button or link, only trough Ajax script function? I want to update my table on onblur or onchange event of a view's table's column textbox
I am using an ajax script to implement this and I am trying to send the data directly to controller through the scriptAnd following is my code:
@foreach (var item in Model)
{
bool aprv = Convert.ToBoolean(item.Approved);
if (aprv)
{
var totp = item.Quantity * Convert.ToInt32(item.Price);
<tr id="myrowID">
<td hidden><input type="hidden" id="quotid" value="@item.QuoteId" /></td>
<td>
@Html.DisplayFor(modelItem => item.SKUMaster.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.SKUMaster.PackagingType)
</td>
<td>
@*@Html.DisplayFor(modelItem => item.Quantity)*@
@Html.DisplayFor(modelItem => item.SKUMaster.Manufacturer)
</td>
<td>
<input type="text" id="itemPrice" name="itemPrice" [email protected] onblur="onPriceChange()"/>
</td>
<td>
<input type="text" id="itemQuantity" name="itemQuantity" value="@item.Quantity" />
</td>
<td>
<label>@totp</label>
</td>
<td>
@Html.DisplayFor(modelItem => item.SupplierMaster.SupplierName)
</td>
<td class="list1">
<a href="#" target="_top">
<img src="~/images/list.png" class="list1" width="17" title="List" height="16" alt="" />
</a>
</td>
</tr>
}
}
<script type="text/javascript" language="javascript">
function onPriceChange() {
var tr = $('#ApprovedTable tr').parent().find('tr:first');
var Price = tr.find("#itemPrice").val();
var Quantity = tr.find("#itemQuantity").val();
var QuoteId = tr.find("#quotid").val();
alert(QuoteId+ Quantity+Price);
$.ajax({
url:'/Quot/EditQuot',
data:{id:'QuoteId',price:'Price',qty:'Quantity'},
type:"POST",
dataType:"json",
traditional:true,
//contentType:'application/json; charset=utf-8',
success: function (data){
alert(data);
}
});
};
</script>
Thanks in advance