2012-08-06 65 views
1

我是新来的Asp.Net MVC,我无法弄清楚如何更新部分视图后的数据。我对GET没有问题,并在局部视图中显示数据。在局部视图中更新数据

我不知道在哪里把部分视图数据的邮政编码放在父页的邮政方法中?或部分视图的后期方法?

当我运行下面的代码时,我提交时会收到此消息。

}

它发现在初始页面加载控制“公共行动方法‘ScoreRelease’是不是在控制‘Registration.Web.Controllers.AgreementsController’。发现”,而不是当我打电话返回查看(“查看”);在post方法中。

Parial查看从 “评论” 页面

@{Html.RenderAction("ScoreRelease", "Agreements");} 

ScoreRelease管窥

@model Registration.Web.Models.ReviewModel.ReleaseScore 
@using (Html.BeginForm()) 
{ 
    @Html.ValidationSummary(true) 


    <div class='group' id='data_release'> 
     <h4> 
      Data Release 
     </h4> 
     <p> 
      Do you wish to release your scores? 
     </p> 
     <ul class='input_group'> 
      <li> 
       @Html.RadioButtonFor(model => model.ReleaseScoreIndicator, true) 
       <label> 
        Yes 
       </label> 
      </li> 
      <li> 
       @Html.RadioButtonFor(model => model.ReleaseScoreIndicator, false) 
       <label> 
        No 
       </label> 
      </li> 
     </ul> 
      <input type="submit" value="Save" /> 
    </div> 


} 

查看控制器

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

    [HttpPost] 
    public ActionResult Review(ReviewModel.ReleaseScore model) 
    { 
     var agmtsService = new AgreementsService(); 
     agmtsService.UpdateReleaseScoreIndicator(model.ReleaseScoreIndicator); 

     return View("Review"); 

    } 

    [HttpGet] 
    public ActionResult ScoreRelease() 
    { 
     var agmtsService = new AgreementsService(); 
     bool scoreRelease = agmtsService.GetReleaseScoreIndicator(); 

     var vm = new ReviewModel.ReleaseScore(); 
     vm.ReleaseScoreIndicator = scoreRelease; 

     return PartialView(vm); 
    } 

回答

1

使用Html.BeginForm与参数称为:

@using (Html.BeginForm("Action", "Controller", FormMethod.Post)) 
0

您必须将Post方法放入部分视图中。您可以通过两种方式执行Html.BeginForm()Ajax.BeginForm。如果您在弹出窗口中显示此部分视图,则最好将其用作Ajax。无论您采取何种行动,您必须使用控制器中的[httppost]标签制作相同的方法名称。