Click here to Skip to main content
15,896,408 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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)
{
     // al code 
     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?
Posted
Updated 12-Feb-20 2:43am

1 solution

When you invoke below return statement, the 2nd parameter should be of type ParentView, because model type of your view is ParentView.
return PartialView("_ReturnView", karta);

Create a new object of type ParentView using contents of variable card, and then pass it to view.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900