2

我是 Asp.Net MVC 的新手,我不知道如何更新部分视图的帖子数据。我对 GET 和在部分视图中显示数据没有问题。

我不确定将部分视图数据的邮政编码放在哪里......在父页面的 post 方法中?还是局部视图的发布方法?

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

“在控制器 'Registration.Web.Controllers.AgreementsController' 上找不到公共操作方法 'ScoreRelease'。”}

它在初始页面加载时找到控制器,但在我调用 return View("Review"); 在 post 方法中。

从“Review”页面调用的 Parial View

 @{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);
    }
4

2 回答 2

1

使用带参数的 Html.BeginForm:

@using (Html.BeginForm("Action", "Controller", FormMethod.Post)) 
于 2012-08-06T19:17:14.127 回答
0

您必须将 Post Method 放在 Partial View 中。您可以通过两种方式进行操作Html.BeginForm()Ajax.BeginForm。如果您在弹出窗口中显示此部分视图,则最好将其用作 Ajax。无论您在视图中放置什么动作,都必须[httppost]在控制器中使用标签创建相同的方法名称。

于 2012-08-06T20:32:49.437 回答