快速但愚蠢的问题。这种级联有点儿。如果我在aspx页面上创建一个变量,它是否可用于我的aspx部分呈现的ascx。另外,aspx页面如何处理这些变量?我知道一个事实,那些变量比说TempData或ViewData变量的持续时间要长得多。下面是我想知道的一个小例子MVC上的变量生命周期页面
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h3><% Response.Write(((ViewData["MESSAGE"] == null) ? "Edit Encounter Information" : ViewData["MESSAGE"]));
int encounter = int.Parse((string)TempData["ENCOUNTID"]);
int PopPatId = int.Parse((string)TempData["POPPATID"]);
int PatID = int.Parse((string)TempData["PATID"]);
int population = (int)TempData["POPULATIONID"];
string templates1 = (string)TempData["TEMPLATES"];
string MRN = ((TempData["MRN"] == null) ? "Add Patient":(string)TempData["MRN"]);
ViewData["TEMPLATES"] = templates1;
%>
</h3>
<div id="countdownDiv" style="display:none">
<p><font color="#990000"><b>Sorry, This Data has expired. Please Refresh The page.</b></font></p>
<%
Html.BeginForm("EditTemplate", "PatientACO", new { Template = PatID, popID = population, PopulationPatID = PopPatId, Enc = encounter });
TempData["TEMPLATES"] = templates1;
%><input type="submit" value="Refresh" id="test" /><%
Html.EndForm();%>
</div>
<% Html.RenderPartial("_EditTemplate"); %>
<%: Html.ActionLink("Back", "TemplateInfo", new { PopulationID = population, ActiveAll = "1" })%>
注意我已经创建的变量。他们会持续多久?我现在可以在下面的ascx页面中使用这些变量吗?
这是今天我见过的最糟糕的代码。你应该把所有的逻辑移动到你的控制器或者视图模型中(取决于逻辑的作用) – jgauffin 2011-12-15 15:17:07