1

Say I have 4 columns in my table. In Mvc list view, I need to add an AJAX call (Ajax.BeginForm) that will update the values of 3rd and 4th column of the table when a button in 3rd column is clicked. Since 'div' cannot be added inside td of the table, I am not clear on how to achieve this (How would I reference my target in UpdateTargetId in Ajax options?)

Here is the part of my view,

@foreach (var item in Model) {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.Num)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Name)
    </td>
    <td>
        <input type="submit" value="x" />
        @Html.DisplayFor(modelItem => item.x)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.y)
    </td>

When the submit button in 3rd column is clicked i need to update both x and y (column 3 and 4) based on the values returned from controller action method. How to achieve this?

coder231
  • 453
  • 2
  • 14
  • Confused. What does `MVC` have to do with what _seems_ to be front-end question? Even the comment about `div` and `table` are strange. Are you asking about how your script can find/modify, etc. some item (aka "selector")? Like `id`, `data-` ? – EdSF Jun 18 '15 at 22:42
  • I have edited the question to add a little more detail. As I wanted to use Ajax.BeginForm helper to call my controller action when a button is clicked , I added MVC tag. In MVC view, I get error when i add 'div' inside a 'td'. My intention is to update 2 of the table columns based on what is returned from controller action method on making Ajax call. – coder231 Jun 18 '15 at 23:03
  • 1
    You can put a [div inside a td](http://stackoverflow.com/questions/2974573/div-inside-table). In this case I think doing a `jQuery.ajax()` instead of using the `Ajax.BeginForm` helper would be easier since you want to update multiple elements on the callback. Also, it would be more helpful if you added the `Ajax.BeginForm` to your code example. – Jasen Jun 19 '15 at 00:35
  • @Jasen Thanks for your suggestion. I used jQuery.ajax() to achieve the result. – coder231 Jun 24 '15 at 19:50

0 Answers0