开发者

MVC datepicker in a grid

开发者 https://www.devze.com 2023-01-15 18:42 出处:网络
I am using the following EditorTemplate which开发者_Go百科 ensure the datepicker is enabled for date fields;

I am using the following EditorTemplate which开发者_Go百科 ensure the datepicker is enabled for date fields;

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" %>
<%:Html.TextBox("", (Model.HasValue ? Model.Value.ToShortDateString() : string.Empty), new { @class = "datePicker" }) %>

However the date is in the partial view following view;

        <fieldset>
        <legend>Enter the bank holidays here:</legend>
        <table>
            <tr>
                <th>Bank Holiday</th>
                <th>Date</th>
                <th>Notes</th>
            </tr>
            <% foreach (var bankHolidayExtended in Model.BankHolidays)
            { %>
                <% Html.RenderPartial("BankHolidaySummary", bankHolidayExtended); %>
            <% } %>
           <tr>
                <td align="center" colspan="3" style="padding-top:20px;"><input type="submit" value="Submit" /></td>
            </tr>
        </table>
        </fieldset>

The partial view looks like this,

    <tr>
        <td><%: Model.T.BankHolidayDescription%></td>
        <td><%: Html.EditorFor(model => model.BH.NullableBankHolidayDate)%></td>
        <td><%: Html.EditorFor(model => model.BH.BankHolidayComment)%></td>
    </tr>

The problem is that the Date field has the same ID for each row. So when you enter a date on row x, it only updates the date on row 1. How do I fix this so that I update the correct row?


Can you do something like this :

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BankHolidays>" %> <%:Html.TextBox("", (Model.HasValue ? Model.NullableBankHolidayDate.ToShortDateString() : string.Empty), new { @class = "datePicker" id = Model.BankID }) %>

And instead sending the editor just Date, you sent him Model with date and bankID :

<td><%: Html.EditorFor(model => model.BH)%></td>

I assume that you have some sort of ID's in your BANK holiday (bankID,bankHolidayID) model. Sorry, I'm not so good at ASP.NET MVC..

0

精彩评论

暂无评论...
验证码 换一张
取 消