This seems to be the cause why the model dialogs for register/logon are shown:
<li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink", data_dialog_title = "Registration" })</li>
<li>@Html.ActionLink("Log on", "LogOn", "Account", routeValues: null, htmlAttributes: new { id = "logonLink", data_dialog_title = "Identification" })</li>
When I reuse those links and modify them slightly to fit my needs for showing a create view dialog I always get my markup embedded/shown in the webpage but not in a dialog.
That is my code I changed slightly:
<p>
@Html.ActionLink("Create News", "Create", "News", routeValues: null, htmlAttributes: new { id = "createLink", data_dialog_title = "Create new News" })
</p>
and thats the original code in the AccountController:
What I do not understand here is where is the "content" coming from? In my Create action for my NewsController I use the same code but content is always null and even when I directly return a PartialView() still no dialog is shown instead the markup is displayed in the webpage?
public ActionResult Create()
{
string actionName = ControllerContext.RouteData.GetRequiredString("action");
if (Request.QueryString["content"] != null)
{
ViewBag.FormAction = "Json" + actionName;
return PartialView();
}
else
{
ViewBag.FormAction = actionName;
return View();
}
}
VIEW: Index.cshtml
@model IEnumerable<TBM.WEB.Models.News>
<p>
@Html.ActionLink("Create News", "Create", "News", routeValues: null, htmlAttributes: new { id = "createLink", data_dialog_title = "Create new News" })
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Title)
</th>
<th>
@Html.DisplayNameFor(model => model.PublishDate)
</th>
<th>
@Html.DisplayNameFor(model => model.Description)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.PublishDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
@Html.ActionLink("Details", "Details", new { id=item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.Id })
</td>
</tr>
}
</table>
PARTIAL-VIEW: Create.cshtml
@model TBM.WEB.Models.News
<script src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>News</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Title)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.PublishDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.PublishDate)
@Html.ValidationMessageFor(model => model.PublishDate)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>