2016-03-23 39 views
0

下面是我的.cshtml中的代碼,並有兩個按鈕,但我無法通過單擊任何按鈕來調用我的操作方法。HttpPost沒有在MVC中點擊保存按鈕後被調用

@model IList<ClaimBuildMVC.ClaimBuildBE.ManageUsersBE> 
@{ 
ViewBag.Title = "GetEditRecord"; 
Layout = "~/Views/Shared/_Layout.cshtml"; 
} 
<div class="Content-inner-pages"> 
<div class="Accountsettings"> 
    <h2><span>Edit User Details</span></h2> 
    <div class="box"> 
     <div class="box-content"> 
      <div class="form-horizontal form-details"> 
       <div class="form-group"> 
        <label class="col-xs-4 col-sm-4 col-md-2 control-label">First Name</label> 
        <div class="col-xs-8 col-sm-8 col-md-4">        
         @Html.TextBox("FirstName", (string)ViewBag.FirstName, new { @class = "form-control", @id = "FirstName" }) 
        </div> 
       </div> 
       <div class="form-group"> 
        <label class="col-xs-4 col-sm-4 col-md-2 control-label">Last Name</label> 
        <div class="col-xs-8 col-sm-8 col-md-4">        
         @Html.TextBox("LastName",(string)ViewBag.LastName, new { @class = "form-control", @id = "LastName" }) 
        </div> 
       </div> 
       <div class="form-group"> 
        <label class="col-xs-4 col-sm-4 col-md-2 control-label">Role</label> 
        <div class="col-xs-8 col-sm-8 col-md-4">        
         @Html.TextBox("RoleName",(string)ViewBag.FkRoleId, 
         new { @class = "form-control", @id = "RoleName" }) 
        </div> 
       </div> 
       <div class="form-group"> 
        <label class="col-xs-4 col-sm-4 col-md-2 control-label">Status</label> 
        <div class="col-xs-8 col-sm-8 col-md-4">       
          @Html.DropDownList("Status", new List<SelectListItem> { new SelectListItem{ Text="Active", Value = "0" },    new SelectListItem{ Text="InActive", Value = "1" } 
      }, new { @class = "form-control" }) 
       </div>     
       </div> 
       <div class="form-group"> 
        <div class="col-xs-8 col-sm-8 col-md-4 col-md-offset-2 col-sm-offset-4 col-xs-offset-4"> 
         <input type="submit" value="Save" name="actiontype" class="btn-class btn-success"> 
         <input type="reset" value="Cancel" name="actiontype" class="btn-class btn-danger"> 
        </div> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 

,在我的控制器

[HttpPost]   
    public ActionResult GetEditRecord(ManageUsersBE MU,string actiontype)   
    { 
     if (actiontype == "Save") 
     { 
my logic 

     } 
     return View("ManageUsersBE"); 
    } 

所以當我把連我的調試器上後,點擊保存按鈕,它不調用到controller.Am我misiing something.Please幫助

+0

包裹內的形式,利用你的HTML無論是普通的HTM l或Html.Begin形式從剃刀 –

+0

@Reddy你可以給我example.i我非常新MVC – Steve

+0

是的,有一個支票 –

回答

2

包裹您從表單中的元素只有這樣,你將能夠發佈。

使用剃刀語法

@using (Html.BeginForm("ACtionName", "ControllerName", FormMethod.Post, new { })) 
{ 
    <div class="form-horizontal form-details"> 
    ..... 
    </div> 
} 

使用純HTML

<form action="/ControllerName/ActionName" method="post">  
    <div class="form-horizontal form-details"> 
     ..... 
    </div> 
</form> 

也看看這個答案https://stackoverflow.com/a/8356569/2592042

+1

感謝隊友..完美的作品。 – Steve

1

你應該使用表單標籤來使HTTPPost工作。

在剃鬚刀使用

在簡單的HTML

你可以做到這一點作爲

<form method="post"> 
//your html 
</form> 
+0

謝謝man.this解決方案也有效。 – Steve