Hi!
I have some difficult time to pass data to Partial view httpPost ActionResult method in Controller.
Let me explain:
1.Have entity which i have been generated with Entity Framework ORM and this looks like this.
<pre lang="c#">
namespace Brasken.Entities
{
using System;
using System.Collections.Generic;
public partial class bras_AllaCarte
{
public int AllaCarteID { get; set; }
public string AllCarteInformation { get; set; }
}
}
2. I have MenyAdminController with folowing methods:
public ActionResult RooleThem()
{
return View();
}
[HttpGet , ChildActionOnly]
public ActionResult _AllaCarte(int id=1)
{
var bras_allacarte = db.bras_AllaCarte.ToList();
return PartialView("_AllaCarte", bras_allacarte);
}
[HttpPost]
[ValidateInput(false)]
public ActionResult _AllaCarte(FormCollection formData, bras_AllaCarte model)
{
if (ModelState.IsValid)
{
try
{
db.Entry(model).State = EntityState.Modified;
db.SaveChanges();
return PartialView("_AllaCarte", model);
}
catch (DataException)
{
ModelState.AddModelError("", "Kunde inte updatera,Prova igen om problemet uppstår igen var god kontakta administratoren.");
}
}
return View();
}
The porpoise of this methods are to use them for administration of brass_AllaCarte entity thru partial view _AllACarte.cshtml , and this looks as folowing:
@model IEnumerable<Brasken.Entities.bras_AllaCarte>
<div class="jumbotron">
@using (Html.BeginForm("_AllaCarte", "MenyAdmin" , FormMethod.Post, null))
{
var item = Model.First();
@Html.HiddenFor(modelItem => item.AllaCarteID)
@Html.TextAreaFor(modelItem => item.AllCarteInformation);
<ul>
<li><a önclick="updateAllaCarteMeny()" class="arrow">Updatera</a></li>
</ul>
<input style="display:none" id="updateAllaCarte" type="submit" value="" />
}
</div>
And att last i have RollThem.cshtml view where i calling a Partial view , and this looks
like this:
<pre lang="xml">@{
ViewBag.Title = "RooleThem";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@{Html.RenderAction("_AllaCarte", "MenyAdmin");}
Problem:
When i debug a project , im geting a right data , but when i need to save changes with HttpPost method model data is null.
What im doing wrong?