0

我遇到了 MVC 3.0 的问题,该问题必须与我的代码有关,但我一直在更改其他人的代码,这些代码刚刚离开公司,似乎搞砸了一些我无法弄清楚的事情。我有一个看起来像这样的控制器:

直接报告提名人

/// <summary>
/// Gets currently logged in user's direct reports nominees
/// </summary>
/// <returns></returns>
[HttpGet]
public ViewResult DirectReportNominees()
{
    this.nominationRepository = new NominationRowsRepository("Data Source=" + MvcApplication.SERVER_NAME + "; Initial Catalog=Cinet;Integrated Security=True",
                                                _currentuser.SAMAccountName);
    return View(nominationRepository.GetDirectReportNominees);
}

/// <summary>
/// Overload that triggers when supervisor clicks
/// Approve or Reject on Direct Report page
/// </summary>
/// <param name="submitButton"> button triggered to accept or Reject nomination</param>
/// <param name="NominationID">ID of nomination to change status of</param>
/// <returns></returns>
[HttpPost]
public ViewResult DirectReportNominees(string submitButton, string NominationID)
{
    this.nominationRepository = new NominationRowsRepository("Data Source=" + MvcApplication.SERVER_NAME + "; Initial Catalog=Cinet;Integrated Security=True",
                                                _currentuser.SAMAccountName);
    switch (submitButton)
    {
        case "Accept":

            NominationRow nomination = nominationRepository.GetNomination(NominationID);
            Employee nominatedUser = _adRepository.GetDirectoryUserInfo(nomination.NomineeLogin);

            // the email is sent from inside the repository
            nominationRepository.AcceptNomination(NominationID, nominatedUser);
            break;
        case "Reject":
            nominationRepository.RejectNomination(NominationID);
            break;
        default:
            break;
    }

    NominationID = "";
    return View(nominationRepository.GetDirectReportNominees);
}

来自数据库类的控制器收集与给定登录用户相关的各种提名报告并将其发送到以下视图

视图如下所示:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<CINet.Areas.CAP.Models.CapDomain.Repositories.NominationStruct>>" %>

<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
<%--<%: CINet.Views.Helpers.CssHelper.Css(Html, "~/Areas/CAP/Styles/Cap.css") %>--%>
<link rel="Stylesheet" type="text/css" href="<%: Url.Content("~/Areas/CAP/Styles/Cap.css") %>" />
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

<div id="outsidewrapper">

<div id="picture"></div>

<div id="insidewrapper">
<div id="navcontainer">
    <% Html.RenderAction("Navigation", "Cap"); %>
</div>
<div id="CapsDashboard">
    <h3>Direct Report Nominees</h3>

        <table>
        <colgroup>
            <col id="nominee" />
            <col id="nominatedBy" />
            <col id="reason" />
            <col id="status" />
        </colgroup>
        <thead>
            <th scope="col">Name</th>
            <th scope="col">Nominated By</th>
            <th scope="col">Reason</th>
            <th scope="col">Status</th>
            <th></th>
        </thead>

       <tbody>
    <% foreach (var nomination in Model) { %>

                <tr>
                    <td><%: nomination.NomineeLogin %></td>
                    <td><%: nomination.NominatedBy %></td>
                    <td><%: nomination.NominationReason %></td>
                    <td><%: nomination.NominationStatus %></td>
                    <td>
                    <% if (nomination.NominationStatus == "Pending")
                       { %>
                       <%--Create Accept Button--%>
                       <% Html.BeginForm("DirectReportNominees", "Cap", FormMethod.Post); %>

                       <%: Html.Hidden("NominationID", nomination.NominationID.ToString()) %>
                       <input type="submit" name="submitButton" value="Accept" />

                       <% Html.EndForm(); %>

                       <%--Create Reject Button--%>
                       <% Html.BeginForm("DirectReportNominees", "Cap", FormMethod.Post); %>

                       <%: Html.Hidden("NominationID", nomination.NominationID.ToString()) %>
                       <input type="submit" name="submitButton" value="Reject" />

                       <% Html.EndForm(); %>

                    <% } %>

                    </td>
                </tr>

            <%--</div>--%>
    <% } %> 
    </tbody>
     </table>
     </div>
     </div>
     </div>
</asp:Content>

显然,这是封装在 SiteMaster 中的。视图接收模型并吐出有关指定用户的各种信息以及拒绝和批准按钮。此按钮值应设置为用户希望执行的特定操作,并且有一个隐藏的输入字段,其值是通过数据库接收的提名 GUID。第一轮效果很好,但是完成之后,当视图从 HttpPost 返回时,所有隐藏的值现在都具有相同的值(GUID)。该值也总是与刚刚批准/拒绝的 GUID 或行相同。关于什么可以保持这个价值的任何想法?没有我可以看到的程序员使用的 ViewData 并且视图中没有错误?我试过逐步浏览视图' 当帖子返回时,s foreach 循环它们都是不同的,但是当它到达浏览器时,它们都是相同的值?非常奇怪且难以确定。

有什么建议么??

视图从中获取的类是:

 public class NominationStruct
    {
        public string NominationID; // unique ID in DB
        public string NomineeLogin;
        public string NominationReason;
        public string NominationReasonWithBreaks;
        public string NominatedBy;
        public string NominationStatus;

    }

模型是:

 public class NominationsListViewModel
    {
        public IList<NominationRow> NominationRows { get; set; }
        public string CurrentTab { get; set; }
    }
4

1 回答 1

0

我的问题通过另一个帖子得到了回答。

这是默认行为。看

http://forums.asp.net/p/1559541/3846605.aspx

于 2011-10-27T21:27:57.697 回答