- I had to convert the method in the controller from HttpGet to HttpPost.
- The method returns a view to me.
- I have previously sent values to this method via ViewBag.
- Currently, when I use ViewBag, an error is thrown:
>Failed to load resource: the server responded with a status of 500 (Internal Server Error)
- The error only pops up when I'm using ViewBag
controller:
[HttpPost]
public ActionResult PartialTabelaEcp(string json)
{
var nr_days= 31;
ViewBag.days= nr_days;
return PartialView("_TableEve");
}
.cshtml
@for (int nr_rows = 0; nr_rows < ViewBag.days; nr_rows++)
{
var nr_names = nr_rows + 1;
}
what I expected?
Help / articles on how to send data from the controller to the view using HttpPost
What I have tried:
for example:
model:
public partial class userDaty_Model
{
public int liczbaDniM { get; set; }
public int numerMiesiacaM { get; set; }
public int numerRokuM { get; set; }
}
controler:
liczbaDni = 1;
numerMiesiaca = 2;
numerRoku= 5;
userDaty_Model userDaty = new userDaty_Model();
userDaty.liczbaDniM = liczbaDni;
userDaty.numerRokuM = numerMiesiaca;
userDaty.numerMiesiacaM = numerRoku;
return PartialView("_TableEve", userDaty);
and now I have for (razor) and how to throw in it the value assigned in the controller?
view
@for (int nr_rows = 0; nr_rows < @aandWhatWriteHere ; nr_rows++)
I tried:
DayValue : @Html.HiddenFor(item => item.userDaty_Model.liczbaDniM);
@for (int nr_rows = 0; nr_rows < DayValue; nr_rows++)