Greetings The issue is that I have a complex model which I am invoking data from 2 normal models to take it to the screen and create a screen with multiple check with the intention of saving them using an ActionResult
Here is the complex model that inherits from other models
namespace SeguridadWeb.Models
{
public class ProfileExtendTypeComplex
{
public ICollection<Type> TypeProfileExtend { get; set; }
public ICollection<ProfileExtended> ProfileExt { get; set; }
}
}
when it is seen, a table is filled using the following line of code
@foreach (var item in Model.TypeProfileExtend)
{
List<ProfileExtended> permiso = (from itemProfileExt in Model.ProfileExt
where itemProfileExt.idProfileExtendedType == item.idType
select itemProfileExt).ToList();
<tr>
<td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
@if (permiso.Count > 0)
{
@Html.Hidden("hdidProfileExtended_" + item.idType.ToString(), permiso[0].idProfileExtended)
}
@Html.Label("label_" + item.idType.ToString(), item.nameType, htmlAttributes: new { @class = "control-label" })
</td>
<td>
@Html.CheckBox("chkProfileExt_" + item.idType.ToString(), permiso.Count > 0 ? Convert.ToBoolean(permiso[0].value) : false, new { @id = "chkProfileExt_" + item.idType.ToString() })
</td>
</tr>
}
with the send button to the controller to perform the data insertion
<input type="submit" value="Crear" class="btn btn-primary pull-right" />
the view is in this way at html level
The problem is when it comes to saving the information I'm getting to the controller as null
this is the controller I'm using
// POST: ProfileViewModel/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([[Bind(Include = "idProfileExtended,idProfileExtendedType,value")] ProfileExtended ProfileExtended)
{
try
{
if (ModelState.IsValid)
{
db.ProfileExtended.Add(ProfileExtended);
db.SaveChanges();
return RedirectToAction("Index");
//}
}
return RedirectToAction("ProfileComplex/CreateEdit");
}
catch
{
return View();
}
}
Any ideas of what could happen or what am I doing wrong?
Thanking you in advance for your help.