Can anyone help? I have a table in my MVC view which shows records from a table in my database. I want to do inline editing of that row's three columns(which are kept as textboxes) and immediately after going focus out of that row, I should be able to pass the updated values to my controller? Is that possible? can I use onblur or onchange events and javascript? how to write javascript for this and how to pass view value to controller using javascript?
Is there other ways to do inline editing?
Jignesh TrivediPosted Jan 22, 2014, 7:18 AM
hi,
yes you can use onblur event.
onblur event you can post data using $.ajax or $.post
but it is not a good idea to to post the data onblur event of each text box.
are you creating grid menually or use any grid control like MVC contrib or web grid?
Jaima JosephPosted Jan 23, 2014, 12:18 AM
Hi Jignesh, thank you for your reply
I amusing the Table,tr,td tags to create my table.
The code is given below:
<table id="ApprovedTable" border="1" cellspacing="0" cellpadding="0" style="width:100%">
<thead>
<tr>
@*
<th>Item Nameth>
<th>Quantityth>
<th>Manufacturerth>
<th>Price <a href="#"><img src="~/images/filter.png" width="15" height="15" alt="" />a>th>
<th>Reorder Quantityth>
<th>Reorder Valueth>
<th>Supplierth>
<th> th>
tr>
thead>
@foreach (var item in Model)
{
bool aprv = Convert.ToBoolean(item.Approved);
if (aprv)
{
var totp = item.Quantity * Convert.ToInt32(item.Price);
<tr><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.EditorFor(modelItem => item.SKUMaster.Manufacturer)*@
@Html.DisplayFor(modelItem => item.SKUMaster.Manufacturer)
td>
<td>
@*@Html.DisplayFor(modelItem => item.Price)*@
@*@Html.TextBoxFor(modelItem => item.Price)*@
<input type="text" id="itemPrice" value="@item.Price" onchange="ValueChanged();"/>
td>
<td>
@*@Html.DisplayFor(modelItem => item.Quantity)*@
@*@Html.TextBoxFor(modelItem => item.Quantity)*@
<input type="text" id="itemQuantity" value="@item.Quantity" onchange="ValueChanged();" />
td>
<td>
@* @Html.DisplayFor(modelItem => item.Quantity)*@
<label>@totplabel>
td>
<td>
@*@Html.DisplayFor(modelItem => item.SupplierMaster.SupplierName)*@
@Html.TextBoxFor(modelItem => item.SupplierMaster.SupplierName)
<input type="text" id="itemSupplier" value="@item.SupplierMaster.SupplierName" onchange="ValueChanged();" />
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>
}
}
table>
In each row I am showing some quotes with its Price ,Quantity details and in the view if I want, I should be able to edit and the changes should be saved. For that I am trying to write a javascript.