Desc:
- I get information from a database using EF
var card= _ecpContext.Card.Where(sth).ToList();
- this gives me information in the List <> format
> card Count = 31
> [0] {App.Models.Card}
> [1] {App.Models.Card}
> [2] {App.Models.Card}
- I want to transfer this data from controller to view
- I am trying to do it like this:
Controller:
[HttpPost]
public async Task<ActionResult> MethodsReturnView(string previously_uploaded_data_from_ajax)
{
return PartialView("_ReturnView", karta);
}
Problem:
- but it throws me an error if it adds 'card' near the returned view
> Failed to load resource: the server responded with a status of 500 (Internal Server Error)
- the error is thrown when the return command is invoked (investigated, red dot)
- without sending this data, the view returns normally
Additionally:
My model:
public partial class Karta_Model
{
[Key]
public int Id { get; set; }
public int? NrDay{ get; set; }
public int? NrMonth { get; set; }
public int? NrYear{ get; set; }
public string? Rozpoczecie { get; set; }
public string? Zakonczenie{ get; set; }
public string? OdbiorGodzin{ get; set; }
...
}
public partial class ParentView
{
public List<Karta_Model> Model1 { get; set; }
}
View:
using AppEcp.Models
@model ParentView
@for (int nr_rows = 0; nr_rows < @ViewBag.daysInMonth; nr_rows++)
{
<tr>
<td>@Html.TextBoxFor(m => m.Model1[nr_rows].Rozpoczecie, new { @class = "start", @type = "time" })</td>
<td>@Html.TextBoxFor(m => m.Model1[nr_rows].Zakonczenie, new { @class = "end", @type = "time" })</td>
<td>@Html.TextBoxFor(m => m.Model1[nr_rows].OdbiorGodzin, new { @class = "gethours", @type = "time" })</td>
</tr>
}
What I have tried:
Questions:
- Is there any other way to send this data from the controller to the view?
- What am I doing wrong here?