my problem is returning Model back to controller... I have got a cooking recipes website. and two Models
public class FeedBackListViewModel
{
public int FeedBackID { get; set; }
public string FoodName{ get; set; }
public List<StepModel> Steps { get; set; }
}
public class Food
{
public int ID {get;set;}
public string FoodName { get; set; }
public string Time { get; set; }
public List<StepModel> Steps { get; set; }
}
public class StepModel
{
public int StepID {get;set;}
public int StepNo { get; set; }
public string StepDetail { get; set; }
public bool Achived { get; set; }
}
public IActionResult Edit(int id)
{
// Imagine i have got a Food[0].Steps{Step1, Step2, Step 3}
each food has different number of Steps.
return View(Food[0]);
}
cshmtl file... I simplified the code for easy read
@model FeedBackListViewModel
<form asp-action="Edit">
<input asp-for="FoodName " class="form-control" />
@foreach (var item in Model.Steps)
{
<tr>
<td>@Html.DisplayFor(model => item.StepID)</td>
<td>@item.StepNo</td>
<td>
<input type="text" id="@item" value="@item.StepDetail" />
</td>
<td><select asp-for="@item.Achivmed">
<option value = yes> Yes </option>
<option value = No> No </option>
</select>
</td>
</tr >
}
[HttpPost]
public IActionResult Edit(FeedBackListViewModel viewModel)
{
// I got my foodName detail correct but Steps are always null.
// I can't retrieve changes on steps.
return View();
}