You must Sign In to post a response.
  • Category: ASP.Net MVC

    Display Error in view for records from datacolumn

    Hi,

    following is a working code that displays record in view using datacolumn and datarow

    <table>
    <thead>
    <tr>
    @foreach (DataColumn col in Model.Columns)
    {
    <th>@col.ColumnName</th>
    }
    </tr>
    </thead>
    <tbody>
    @foreach (DataRow row in Model.Rows)
    {
    <tr>
    @foreach (DataColumn col in Model.Columns)
    {
    <td>@row[col.ColumnName]</td>

    }
    <td> @Html.ActionLink("Edit", "Edit") |</td>
    </tr>
    }
    </tbody>
    </table>

    my problem is i can't add an in edit field.in this example first column of every row contains id .

    i want to add id to edit field like this

    <td> @Html.ActionLink("Edit", "Edit"), new { id=col[0] } |</td>

    i tried it several times ,yet to succeed.

    Regards

    Baiju
  • #751274
    Hello baiju,

    Have you debug that you have an id in col[0] column?
    If yes, than try this.

    @Html.ActionLink("Edit", "Edit", new { id=row[0] })

    I hope this will help you,
    If you still have an issue regarding that than i'll get back to you.

    Regards,
    Nirav Prabtani (Senior Web Developer)
    Email : niravjprabtani@gmail.com
    blog : niravprabtani.blogspot.in

  • #751283
    use ViewBag to store error and on form

    using (Html.BeginForm("form_edit", "Form", FormMethod.Post))
    {
    <table>
    <tr>
    <td>
    @ViewBag.error
    @Html.ValidationMessage("error_msg")
    </td>
    </tr>
    <tr>
    <th>
    @Html.DisplayNameFor(model => model.content_name)
    @Html.DropDownListFor(show content from datatable columns)
    </th>
    </tr>
    </table>
    }

    Hope it helps

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #751326
    Hello
    You have to add

    @Html.ActionLink("Update", "Edit", new { id = @row[ID] })


    Hope it will help


  • Sign In to post your comments