Asp.net mvc POST方法不适用于MVC4

Asp.net mvc POST方法不适用于MVC4,asp.net-mvc,asp.net-mvc-4,post,Asp.net Mvc,Asp.net Mvc 4,Post,我试着在我的桌面艺术中创建一篇新文章,但是POST方法不起作用,我现在不知道为什么,编辑文章效果很好,我读了很多关于这个主题的帖子,什么都没有,我希望任何人都能帮我 模型 控制岗位法 看法 渲染部分 谢谢你帮我解决这个问题 代码中有嵌套表单,这导致了此问题。Submit按钮位于内部,但它没有任何可调用的控制器和操作方法,因此它不会将数据发布到任何方法 因此,您需要更改以下代码: 看法 什么不起作用?您是否尝试在创建函数中设置一些制动点?您有两个嵌套表单,这是问题所在,因此单独的表单可以工作,但嵌

我试着在我的桌面艺术中创建一篇新文章,但是POST方法不起作用,我现在不知道为什么,编辑文章效果很好,我读了很多关于这个主题的帖子,什么都没有,我希望任何人都能帮我

模型

控制岗位法

看法

渲染部分


谢谢你帮我解决这个问题

代码中有嵌套表单,这导致了此问题。Submit按钮位于内部,但它没有任何可调用的控制器和操作方法,因此它不会将数据发布到任何方法

因此,您需要更改以下代码:

看法


什么不起作用?您是否尝试在创建函数中设置一些制动点?您有两个嵌套表单,这是问题所在,因此单独的表单可以工作,但嵌套表单无法工作,但您这样做是错误的。在局部视图或主视图中使用表单
public class Art
{        
    [Key]
    public int idArt { get; set; }
    [DisplayName("Codigo Artículo")]
    [Required(ErrorMessage = "Codigo Artículo Requerido")]
    [MaxLength(30)]
    public string co_art { get; set; }

    [DisplayName("Tipo Articulo")]
    [ForeignKey("TypeArticles")]
    [Required(ErrorMessage = "Tipo Artículo Requerido")]
    public int IDType { get; set; }
    public virtual TypeArticles TypeArticles { get; set; }

    [DisplayName("Descripción")]
    [Required(ErrorMessage = "Descripción Artículo Requerido")]
    [MaxLength(150)]
    public string des_art { get; set; }
    [DisplayName("Modelo")]
    [Required(ErrorMessage = "Modelo Artículo Requerido")]
    [MaxLength(50)]
    public string modelo { get; set; }
    [DisplayName("Referencia")]
    [MaxLength(50)]
    [Required(ErrorMessage = "Referencia Artículo Requerido")]
    public string referencia { get; set; }
    [DisplayName("Linea Artículo")]
    [ForeignKey("Linea")]
    [Required(ErrorMessage = "Linea Artículo Requerido")]
    public int IdLinea { get; set; }
    public virtual Linea Linea { get; set; }
    [DisplayName("Categoria Artículo")]
    [ForeignKey("Categoria")]
    [Required(ErrorMessage = "Categoria Artículo Requerido")]
    public int idCat { get; set; }
    public virtual Categoria Categoria { get; set; }        

    [DisplayName("Precio Venta")]
    [Range(0.01, 999999999, ErrorMessage = "Precio debe estar entre 0.01 y 999999999")]
    public double Price { get; set; }

    [MaxLength(1024)]
    [DisplayName("Info. Adicional")]
    public string Adicional { get; set; }

    [MaxLength(100)]
    public string Photo { get; set; }
}
    [HttpPost]
    [ValidateInput(false)]
    public ActionResult Create(Art artmodels)
    {
        ViewBag.idLinea = new SelectList(db.Linea.OrderBy(c => c.des_lin), "IdLinea", "des_lin");
        ViewBag.IdCat = new SelectList(db.Categorias.OrderBy(c => c.des_cat), "IdCat", "des_cat");
        ViewBag.IDType = new SelectList(db.TypeArticles.OrderBy(c => c.TypeDesc), "IDType", "TypeDesc");

        if (ModelState.IsValid)
        {
            var art_exists = (from inv in db.Art where inv.co_art == artmodels.co_art.Trim() select inv).FirstOrDefault();
            if (art_exists != null)
            {
                ModelState.AddModelError("co_art", "Codigo de Articulo ya Existe");
                return View(artmodels);
            }

            db.Art.Add(artmodels);
            db.SaveChanges();
            ///
            //int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
            //var articulos = db.Art;

            //IPagedList<Art> art_paged = null;
            //art_paged = articulos.OrderBy(i => i.co_art).ToPagedList(currentPageIndex, (pagesize.HasValue) ? pagesize.Value : defaultPageSize);

            return RedirectToAction("Edit", "Articulos", new {id = artmodels.idArt });                
        }       

        this.Response.StatusCode = 400;
        return View(artmodels);
    }
@model mvcAmerica.Models.Art
@{
    ViewBag.Title = "Creacion";
}

<h1><small>Creación Articulos</small></h1>

@using (Html.BeginForm("Create", "Articulos", FormMethod.Post))
{
    @Html.ValidationSummary(true)
    <text>
        @{Html.RenderPartial("CreateOrEditArticulos", Model);}
    </text>
}
@model mvcAmerica.Models.Art


@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
<fieldset>
    @Html.HiddenFor(model => model.idArt)

        <div class="clearfix">
            @Html.LabelFor(model => model.co_art)

            <div class="input">
                @Html.EditorFor(model => model.co_art)
                @Html.ValidationMessageFor(model => model.co_art)
            </div>
        </div>

    <div class="clearfix">
        @Html.LabelFor(model => model.des_art)

        <div class="input">
            @Html.EditorFor(model => model.des_art)
            @Html.ValidationMessageFor(model => model.des_art)
        </div>
    </div>

    <div class="clearfix">
        @Html.LabelFor(model => model.IDType, "Tipo Articulo")

        <div class="input chosen-select">
            @Html.DropDownList("IDType", String.Empty)
            @Html.ValidationMessageFor(model => model.IDType)
        </div>
    </div>

    <div class="clearfix">
        @Html.LabelFor(model => model.modelo)

        <div class="input">
            @Html.EditorFor(model => model.modelo)
            @Html.ValidationMessageFor(model => model.modelo)
        </div>
    </div>

    <div class="clearfix">
        @Html.LabelFor(model => model.referencia)

        <div class="input">
            @Html.EditorFor(model => model.referencia)
            @Html.ValidationMessageFor(model => model.referencia)
        </div>
    </div>

    <div class="clearfix">
        @Html.LabelFor(model => model.IdLinea)

        <div class="input chosen-select">
            @Html.DropDownList("IdLinea", String.Empty)
            @Html.ValidationMessageFor(model => model.IdLinea)
        </div>
    </div>

    <div class="clearfix">
        @Html.LabelFor(model => model.idCat)

        <div class="input chosen-select">
            @Html.DropDownList("IdCat", String.Empty)
            @Html.ValidationMessageFor(model => model.idCat)
        </div>
    </div>

    <div class="clearfix">
        @Html.LabelFor(model => model.Price)
        <div class="input">
            @Html.EditorFor(model => model.Price)
            @Html.ValidationMessageFor(model => model.Price)
        </div>
    </div>


    <div class="clearfix">
        @Html.LabelFor(model => model.Adicional)

        <div class="input">
            @Html.EditorFor(model => model.Adicional)
            @Html.ValidationMessageFor(model => model.Adicional)
        </div>
    </div>

    <div class="actions">
        <input type="submit" class="btn primary" value="Guardar" />
        @Html.ActionLink("Listado", "Index", null, new { @class = "btn" })
    </div>
</fieldset>
}
@model mvcAmerica.Models.Art
@{
    ViewBag.Title = "Creacion";
}

<h1><small>Creación Articulos</small></h1>

//the commented line should go to the partial view
//@using (Html.BeginForm("Create", "Articulos", FormMethod.Post))
//{
//    @Html.ValidationSummary(true)
    <text>
        @{Html.RenderPartial("CreateOrEditArticulos", Model);}
    </text>
@model mvcAmerica.Models.Art

@using (Html.BeginForm("Create", "Articulos", FormMethod.Post))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

   // rest of the code is as it is
}