HttpPost不起作用

时间:2017-10-01 19:05:26

标签: asp.net asp.net-mvc-4

这是我的观点

@model WebApplication6.Models.User
....
<div class="panel panel-default">
    <div class="panel-body">
        <div class="row">
            @using (Html.BeginForm("CalisanEkle", "Home", FormMethod.Post))
            {
                <div class="form-group">
                    <label>Adı</label><br />
                    @Html.TextBoxFor(m => m.Name, new { @class = "form-control" })

                </div>
                <div class="form-group">
                    <label>Soyadı</label>
                    @Html.TextBoxFor(m => m.Surname, new { @class = "form-control" })
                </div>
                <div class="form-group">
                    <label>Mail Adresi</label>
                    @Html.TextBoxFor(m => m.MailAdress, new { @class = "form-control" })
                </div>
                <div class="form-group">
                    <label>Çeviri Türü</label>
                    <label class="checkbox-inline">
                        @Html.CheckBoxFor(m => m.Teknik.Value, false)Teknik
                    </label>
                    <label class="checkbox-inline">
                        @Html.CheckBoxFor(m => m.Medical.Value, false)Medikal
                    </label>
                    <label class="checkbox-inline">
                        @Html.CheckBoxFor(m => m.Hukuk.Value, false)Hukuk
                    </label>
                    <br />
                    <button type="submit" value="Save" class="btn btn-default">Kaydet</button>
                    <button type="reset" class="btn btn-default">Sil</button>
                </div>
            }
        </div>
    </div>
    <!-- /.row (nested) -->
</div>
<!-- /.panel-body -->

控制器

public class HomeController : Controller
{
    WebApplication6.Models.Entities db = new Models.Entities();

    [HttpPost]
    public ActionResult CalisanEkle(User kisi)
    {
        db.User.Add(kisi);
        db.SaveChanges();
        return View();
    }
    public ActionResult CalisanEkle()
    {
        return View();
    }
} 

现在点击我的提交按钮,它应该运行[HttpPost]控制器吗?好吧,它没有运行。它运行get控制器。我使用断点来确保它不会进入帖子行。几个小时试了好几件事。有人能帮帮我吗?

模型

public partial class User
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public User()
    {
        this.Lang_User = new HashSet<Lang_User>();
        this.Login = new HashSet<Login>();
        this.Projects = new HashSet<Projects>();
        this.WorkLoad = new HashSet<WorkLoad>();
    }

    public int ID { get; set; }
    public string MailAdress { get; set; }
    public string Name { get; set; }
    public string SurName { get; set; }
    public Nullable<System.DateTime> BirthDate { get; set; }
    public Nullable<System.DateTime> StartDate { get; set; }
    public byte[] Picture { get; set; }
    public Nullable<int> CompanyID { get; set; }
    public Nullable<bool> PC { get; set; }
    public Nullable<bool> Admin { get; set; }
    public Nullable<bool> Cevirmen { get; set; }
    public Nullable<bool> Reductor { get; set; }
    public Nullable<bool> Teknik { get; set; }
    public Nullable<bool> Medical { get; set; }
    public Nullable<bool> Hukuk { get; set; }

    public virtual Company Company { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Lang_User> Lang_User { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Login> Login { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Projects> Projects { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<WorkLoad> WorkLoad { get; set; }
}

web.config.cs

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

1 个答案:

答案 0 :(得分:0)

我向所有试图帮助我的人道歉。我的哑巴*将渲染体放在布局页面中的一个表单中。这就是当你不休息时会发生错过非常明显的事情。

 <form id="form1" runat="server">
        <div id="page-wrapper" style="min-height: 904px">

           @RenderBody()
        </div>
    </form>