I have the following model:

public class Card
{        
    [DataType(DataType.Date)]
    [BindProperty]
    public DateTime Day { get; set; }

    [BindProperty]
    public string Field { get; set; }
}

The following Controller:

// GET: Card
public async Task<IActionResult> Index(DateTime? day)
{
    return View(model);
}

public async Task<IActionResult> Refresh(DateTime? Day, string Field)
{
     return RedirectToAction("Index", Day);
}

The following View:

@model Card

<h1>Cards</h1>
<div class="text-center">
    <label asp-for="Day" class="control-label"></label>
    <input asp-for="Day" class="form-control" />
</div>
<div class="text-center">
    <label asp-for="Field" class="control-label"></label>
    <select asp-for="Field" class="form-control" asp-items="ViewBag.Fields"></select>
</div>
<form asp-action="Refresh">
    @Html.HiddenFor(x => x.Day)
    @Html.HiddenFor(y => y.Field)
    <input type="submit" value="Refresh" class="btn btn-default" />
</form>

No matter what I change, I always get the initial Day value back and null as the Field, like the Model has never been changed…

So how can I post back the modified model to my controller?

Related posts

Recent Viewed