English 中文(简体)
MVC3 不发射的局部观察方法
原标题:MVC3 Partial view method not firing

我有部分观点(关于用户名称、密码和分门纽顿的行文记录仪),而部分意见则在我的休庭上使用。

So, on my _layout page, I have:

<div style="text-align: right">
    @Html.Partial("_LoginPartial")
</div>

我的——总行有以下法典:

    @if (Request.IsAuthenticated)
{
    <textarea>Welcome!
        [ @Html.ActionLink("Log Off", "Logout", "Account")]</textarea>

}
else
{
    @Html.Partial("~/Views/Account/Index.cshtml")
}

显示标识箱的指数文件就是这样:

  @using GalleryPresentation.Models
@model LoginModel

<script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script>
@using (Html.BeginForm("index", "Account"))
{
    <table>
        <tr>
            <td>@Html.LabelFor(m => m.Username)</td>
            <td>@Html.TextBoxFor(m => m.Username)</td>
        </tr>
        <tr>
            <td>@Html.LabelFor(m => m.Password)</td>
            <td>@Html.PasswordFor(m => m.Password) kjkj</td>
        </tr>
        <tr>
            <td colspan="2"><input type="submit" value="Login"/></td>
        </tr>
        <tr>
            <td colspan="2">@Html.ValidationSummary()</td>
        </tr>
    </table>

}

我的账户 我有以下法典:

public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Index(LoginModel loginModel)
    {
        if(ModelState.IsValid)
        {
            var g = new GallaryImage();
            var user = g.LoginUser(loginModel.Username, loginModel.Password);
            if(user != null) 
            {
                FormsAuthentication.SetAuthCookie(user.username, false);
                return RedirectToAction("Index", "Home");
            }
            ModelState.AddModelError("", "Invalid Username/Password");
        }
        return View(loginModel);
    }

    public ActionResult Logout()
    {
        FormsAuthentication.SignOut();
        return RedirectToAction("Index", "Home");
    }

I have breakpoints on all methods - but they never get hit. Pressing the submit button simply changes my URL to:

http://localhost:8741/?Username=myusername&Password=mypassword

谁能发现我正在制造的错误?

最佳回答

Since Html.BeginForm defaults to making GET requests, you are making a GET request with from your view. However, your action only accepts POST requests.

You can change @using (Html.BeginForm("index", "Account")) to @using (Html.BeginForm("index", "Account", FormMethod.Post)).

问题回答

暂无回答




相关问题
Very basic WPF layout question

How do I get this listbox to be maxiumum size, i.e. fill the group box its in. I ve tried width="auto" Height="auto", width="stretch" Height="stretch" annoyingly at the moment, it dynamicly sizes to ...

How to align the text to top of TextView?

How to align the text to top of a TextView? Equivalent Android API for Swings setInsets()? that is top of text should start be in (0,0) of TextView <?xml version="1.0" encoding="utf-8"?> <...

Centring a flow in Shoes

Can I center the contents of a flow in Shoes? I know that a paragraph can be centred like: para Centred paragrpah , :align=> center However, this does not work with flows: flow(:align=> ...

Overlaying with CSS

I want to load a website in an iframe, and overlay the website with some hints about the website that is shown. However, i got stuck at the point that the website has a variable passive white space at ...

How do you normally make a program look beautiful? [closed]

How can I make an Application look nice and not like an amateur pulled it together? I mean graphic-wise. Is there some sort of book you can read regarding beautiful program layouts, etc? I put this ...

热门标签