asp.net mvc 4 [HttpPost]不起作用 [英] asp.net mvc 4 [HttpPost] not working

查看:257
本文介绍了asp.net mvc 4 [HttpPost]不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是asp.net MVC 4的新手.我在处理属性时遇到一些问题

I am new to asp.net MVC 4. i have some problems dealing with attributs

我在控制器中使用了[httppost]属性,但是它不起作用

i use [httppost] attribut in my controller but it's not working

它甚至没有被调用

我的控制器

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


    [HttpPost]
    public ActionResult Inscription(Candidat candidat)
    {
        if (!ModelState.IsValid)
        {
            return View(candidat);

        }

        return RedirectToAction("Index");
    }

我的观点

     @model ProcRec.Models.Candidat

     @{
     ViewBag.Title = "Inscription";
     Layout = "~/Views/Shared/_Layout.cshtml";
      }


      @Html.ValidationSummary(true) 
     <div class="form_settings">
      @using (Html.BeginForm("Inscription", "CandidatController"))
      { 

      <table ="#FFFFFF">
      <tr>

      <td>@*<span >Nom :</span>*@ @Html.LabelFor(model => model.nom_candidat)</td>

      <td> @Html.TextBoxFor(model => model.nom_candidat)
            @Html.ValidationMessageFor(Model => Model.nom_candidat)     

             .

             .

       </table>

       }
  <input type="submit"  class="submit right"  value="Inscription" /> 

想想您的帮助

推荐答案

只需将beginform正确设置为:

Just correct beginform as :

@using (Html.BeginForm("Inscription", "CandidatController",FormMethod.Post))
{ 
  ........
  <input type="submit"  class="submit right"  value="Inscription" /> 
}

将提交按钮置于BeginForm()内,并将BeginForm()FormMethod设置为Post.

Put submit button inside BeginForm() and give BeginForm() FormMethod as Post.

谢谢.

这篇关于asp.net mvc 4 [HttpPost]不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆