1

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>
tereško
  • 58,060
  • 25
  • 98
  • 150
msfanboy
  • 5,273
  • 13
  • 69
  • 120
  • Please post your view and partial view. – Maess Dec 05 '11 at 20:32
  • Yes I have a News model. As I said the markup/view is shown as a partial inside the page, but not in the dialog, but I use the same code the register/logon uses from the asp.net mvc 4.0 sample project. I updated my initial post with view code! – msfanboy Dec 05 '11 at 20:37
  • Ok, what are the names of the view and partial view? Do you have a Create view for News? – Maess Dec 05 '11 at 20:39
  • I found out that both register/logon links ids 'registerLink' and 'logonLink' are also written in the AjaxLogix.js file which I thought its a jquery library but it seems to be a helper classes. I added my 'createLink' but it does not help... seems the AjaxLogin.js is not used... – msfanboy Dec 05 '11 at 20:52
  • Does this functionality have to be a modal popup? – Maess Dec 05 '11 at 20:53
  • yes I want all Create/Edit as modal dialogs and actually it should work the way register/logon work magically somehow... – msfanboy Dec 05 '11 at 20:56
  • possible duplicate of [Jquery Modal Dialog displaying MVC3 partial view - works first click only](http://stackoverflow.com/questions/6296720/jquery-modal-dialog-displaying-mvc3-partial-view-works-first-click-only) – msfanboy Dec 05 '11 at 21:13
  • Don't you find a solution for this problem? I'm facing the same problem right now. Thanks for feedback. – Bronzato Feb 15 '12 at 13:58

1 Answers1

1

I believe you may need to take a look at the AjaxLogin.js file within the Scripts folder of the sample project. It will need some customization as there is a list of link ids that will utilize a dialog.

G_P
  • 2,100
  • 3
  • 16
  • 18
  • 1
    seems someone has the same problem http://stackoverflow.com/questions/6296720/jquery-modal-dialog-displaying-mvc3-partial-view-works-first-click-only I close this thread now as its a dupe! – msfanboy Dec 05 '11 at 21:12