문제

I have a layout page with the following

_app.cshtml

<div id="top_right">
    @{ Html.Partial("_LogOnPartial"); }
</div>

The log on partial contains

_LogOnPartial.cshtml

@{
    Layout = null;
}

@if (Request.IsAuthenticated)
{
    Html.RenderAction("Details", "Account");
}
else
{
    Html.RenderAction("LogOn", "Account");
}

and the render action method im expecting to see is

AccountController.cs

public class Account
{  
        public PartialViewResult LogOn()
        {
            return PartialView();
        }
}

the Logon partial view that would be returned by Account/LogOn is

LogOn.cshtml

@model Presentation.Models.LogOnModel

<div id="login">
    @Html.ValidationSummary()

    <h2>Start by Loggin in</h2>

    @using (Html.BeginForm("LogOn", "Account"))
    {
        @Html.Hidden("returnUrl", Request.Url.PathAndQuery)

        <table width="100%" border="0" cellspacing="0" cellpadding="5">
            <tr>
                <td>
                    <span class="bluey">Username:</span><br />
                    @Html.TextBoxFor(m => m.UserName, new {tabindex = "1", Class = "field"})
                    @Html.ValidationMessageFor(m => m.UserName, "*")
                </td>
                <td>
                    <span class="bluey">Password:</span><br />
                    @Html.TextBoxFor(m => m.Password, new {tabindex = "2", Class = "field"})
                    @Html.ValidationMessageFor(m => m.Password, "*")
                </td>
            </tr>
            <tr>
                <td>
                    <input name="login" type="submit" value="Submit" class="input_btn" tabindex="3" />
                </td>
                <td>@Html.CheckBoxFor(m => m.RememberMe) @Html.LabelFor(m => m.RememberMe) <span class="bluey">&nbsp; | &nbsp;</span> @Html.ActionLink("Forgot Password?", "Password", "User")></td>
            </tr>
        </table>
    }
</div>

I have traced the flow through and I can see it is hitting the

Html.RenderAction("LogOn", "Account")

and returning the partial view from there however when I view the page none of the html of the partial view (LogOn.cshtml) is rendered, it isn't even present in the source.

Am I missing something fundamental here, is there a better way to achieve this?

도움이 되었습니까?

해결책

You have a code block which will be returning the partial rather than outputting it, change:

<div id="top_right">
    @{ Html.Partial("_LogOnPartial"); }
</div>

to:

<div id="top_right">
    @Html.Partial("_LogOnPartial");
</div>

Alternatively, use Html.RenderPartial to output it directly.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top