替换为Html.BeginForm()

时间:2013-12-19 22:49:08

标签: c# asp.net-mvc twitter-bootstrap view

我使用bootstrap在我的MVC 4应用程序中创建登录视图。 它的工作但是我的登录视图:

@using (Html.BeginForm())
{
    <link href="~/Content/dist/css/signin.css" rel="stylesheet">
    <div class="container">
        <form class="form-signin" role="form">
            <h2 class="form-signin-heading">Entrar</h2>
            <input type="text" id="User" name="UserName" class="form-control" placeholder="Usuário"   required />
            <input type="password" id="Pass" name="Password" class="form-control" placeholder="Senha" required>
            <button class="btn btn-lg btn-primary btn-block" type="submit">Entrar</button>
        </form>
    </div>
}

但是css的引用是'link href="~/Content/dist/css/signin.css" rel="stylesheet'行,但它只有在我删除@Html.BeginForm()时才有效,但是当我创建{{{}}时我无法触发我的动作1}}。

如何在没有HttpPost的情况下调用我的操作?

2 个答案:

答案 0 :(得分:3)

我现在可以看到你在彼此内部使用了两种形式。你应该删除bootstrap,并确保BeginForm发出正确的表单:

    <link href="~/Content/dist/css/signin.css" rel="stylesheet">
    <div class="container">
        @using (Html.BeginForm("your-action", "your-controller", 
                               FormMethod.Post, 
                               new { @class="form-signin", role = "form} ))
        {
            <h2 class="form-signin-heading">Entrar</h2>
            <input type="text" id="User" name="UserName" class="form-control" placeholder="Usuário"   required />
            <input type="password" id="Pass" name="Password" class="form-control" placeholder="Senha" required>
            <button class="btn btn-lg btn-primary btn-block" type="submit">Entrar</button>
        }
    </div>

答案 1 :(得分:1)

将评论中指示的链接移至<head>,但解析href值,如下所示:

 <link href="@Url.Content("~/Content/dist/css/signin.css")" rel="stylesheet" type="text/css" />