我有一个选项卡的窗体。 从属于每个标签是一个局部视图。 当用户提交保存更改,我想呼吁的局部视图的方法,所以对于局部视图我把<%使用(Html.BeginForm(...)%>,但这被忽略,并点击提交意志调用与容器视图,而不是关联的方法。这是为什么,以及如何得到这个工作?


<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Employee.Master" Inherits="System.Web.Mvc.ViewPage<SHP.WebUI.Models.HolidayRequestViewModel>" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> HolidayRequest </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="EmployeeContent" runat="server"> <% using (Html.BeginForm()) {%> <%: Html.AntiForgeryToken() %> <h2>Holiday Request</h2> <p>You have <%: Html.DisplayFor(model => model.DaysAvailableThisYear) %> days left annual leave for this year and <%: Html.DisplayFor(model => model.DaysAvailableNextYear) %> days left for next year.</p> <p>If your request is approved and exceeds the number of days left, then those extra days will not be paid.</p> <div id="tabs"> <ul> <li><a href="#tabs-1">Approver</a></li> <li><a href="#tabs-2">Single Date</a></li> <li><a href="#tabs-3">Date Range</a></li> </ul> <div id="tabs-1"> <% Html.RenderPartial("GetApproverTab", Model); %> </div> <div id="tabs-2"> <% Html.RenderPartial("GetSingleDateTab", Model); %> </div> <div id="tabs-3"> <% Html.RenderPartial("GetDateRangeTab", Model); %> </div> </div> <%: Html.HiddenFor(x => x.EmployeeId) %> <% } %> </asp:Content>


<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<SHP.WebUI.Models.HolidayRequestViewModel>" %> <% using (Html.BeginForm("GetSingleDateTab", "Employee", FormMethod.Post, new { id = "frmSingleDate" })) { %> <p>Enter your day or part day of Annual Leave here.</p> <table> <tr> <td align="right">Date:</td> <td><%: Html.EditorFor(x => x.SingleDate) %></td> </tr> <tr> <td align="right">Morning Only:</td> <td><%: Html.CheckBoxFor(x => x.MorningOnlyFlag) %></td> </tr> <tr> <td align="right">Afternoon Only:</td> <td><%: Html.CheckBoxFor(x => x.MorningOnlyFlag) %></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Save" /></td> </tr> </table> <% } %>


#region Employee Holiday Request public ActionResult HolidayRequest() { return View(new HolidayRequestViewModel(Employee.GetLoggedInUser().EmployeeId)); } [HttpPost] // This is the method that gets executed public ActionResult HolidayRequest(HolidayRequestViewModel hrvm) { if (ModelState.IsValid) { hrvm.Update(); return View(new HolidayRequestViewModel(hrvm.EmployeeId)); } return View(hrvm); } [HttpPost] // This is the method I want to get executed. public ActionResult GetSingleDateTab(HolidayRequestViewModel hrvm) { if (ModelState.IsValid) { hrvm.Update(); return View(new HolidayRequestViewModel(hrvm.EmployeeId)); } return View("GetSingleDateTab", hrvm); } #endregion



分类 mvc的 时间:2015-03-15 人气:5
本文关键词: mvc的


Copyright (C), All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.486 (s). 10 q(s)