I have the following:
_ImageGalleryPartial
@if (Model != null)
{
foreach (var item in Model)
{
@Html.Partial("_ImageItem", item);
}
}
_ImageItemPartial
@model WebsiteEngine.Models.PortfolioImage
@{
string url = VirtualPathUtility.ToAbsolute(String.Format("~/{0}", Html.DisplayFor(m => m.FileName)));
}
@using (Html.BeginForm("DeleteImage", "Portfolio", FormMethod.Post, new { @class = "deleteImageForm" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true);
@Html.HiddenFor(m => m.Name)
@Html.HiddenFor(m => m.FileName)
@Html.HiddenFor(m => m.Order)
@Html.HiddenFor(m => m.PortfolioID)
@Html.HiddenFor(m => m.PortfolioImageID)
<div class="span3">
<div class="item">
<a class="fancybox-button" data-rel="fancybox-button" title="Photo" href="@url">
<div class="zoom">
<img src="@url" alt="Photo" />
<div class="zoom-icon"></div>
</div>
</a>
<div class="details">
<a href="#" class="icon deleteImage" data-form=""><i class="icon-remove"></i></a>
</div>
</div>
</div>
}
When I inspect the page elements using Chrome dev tools, the first element is missing the surrounding form. If I inspect the page source (using right) click then the form is there. This lead me to believe some JS was removing the form so I disabled JS but it was still missing.
If change _ImageGalleryPartial so it's like this (notice the addition of an empty model):
@if (Model != null)
{
@Html.Partial("_ImageItem", new WebsiteEngine.Models.PortfolioImage());
foreach (var item in Model)
{
@Html.Partial("_ImageItem", item);
}
}
Then all the "correct" elements get a form but again, this first item doesn't.
I'm still inclined to think this is a JS issue but I'm a little stumped as disabling JS doesn't fix it. Is this some off behaviour with MVC?
Just to note, I have simplified my layout above, I do actually have one or 2 nested forms but assume that's Ok as everything else is Ok, it's just this first partial that's broken.
Any ideas?