Linked Questions

Popular Questions

Send date values to controller from cshtml page

Asked by At

I'm using .NetCore and Entity Framework to design a site.

On the site, I have a cshtml page that displays a table of data like this:

@foreach (var item in Model) {
                @Html.DisplayFor(modelItem => item.CharacterId)
                @Html.DisplayFor(modelItem => item.CharacterDisplayName)
                @Html.DisplayFor(modelItem => item.TimePathYear)

                <a asp-action="Edit" asp-route-id="@item.CharacterId">Edit</a> |

Where, when the user clicks on the "Edit" link, it will send them to this controller:

public async Task<IActionResult> Edit(int? id) { }

However, I now want to pass in a user-selectable date range so that the controller would look like this:

public async Task<IActionResult> Edit(int? id, DateTime? start, DateTime? end) { }

So I added these two date controls to the cshtml page:

    <div class="datePickers">
        <div class="startDate">
            Start Date
            <input id="inputStartDate" type="date" asp-format="{0:yyyy-MM-dd}"/>
        <div class="endDate">
            End Date
            <input id="inputEndDate" type="date" asp-format="{0:yyyy-MM-dd}"/>
            <button formaction="/Characters/Index/">Go</button>

But how would I add the date values they select to the asp-action?


Related Questions