我有MVC4 Web應用程序,我在.cshtml頁面內渲染了部分視圖(.ascx)。我添加了一個具有OnSelectedIndexChanged的下拉列表,它永遠不會觸發。請參閱下面DropDownList OnSelectedIndexChanged不會觸發
代碼Dashboard.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Dashboard.ascx.cs" Inherits="iSPYCMS.Views.Dashboard" EnableViewState="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Charts Example</title>
</head>
<body style="padding:50px;background-color:white">
<form id="form1" runat="server">
<asp:DropDownList runat="server" ID="cmbTypeSeletion" Height="16px" Width="190px" EnableViewState="true" Enabled="true" OnSelectedIndexChanged="cmbTypeSeletion_SelectedIndexChanged">
<asp:ListItem Enabled="true" Text="Downloads" Value="Downloads"> </asp:ListItem>
<asp:ListItem Enabled="true" Text="Plays" Value="Plays"></asp:ListItem>
<asp:ListItem Enabled="true" Text="Completion" Value="Completion"></asp:ListItem>
</asp:DropDownList>
<div>
<script type="text/javascript" src="https://www.google.com/jsapi"> </script>
<asp:Literal ID="ltScripts" runat="server"></asp:Literal>
<div id="chart_div">
</div>
</div>
</form>
</body>
</html>
Dashboard.ascx.cs
namespace iSPYCMS.Views
{
public partial class Dashboard : ViewUserControl
{
protected void cmbTypeSeletion_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
Index.cshtml
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div>
@Html.Partial("~/Views/Dashboard.ascx")
</div>
您正在混合webforms與MVC ..不好 – giammin
是的,我知道其實我不得不使用谷歌圖表,我找不到任何MVC的好例子,所以我使用用戶控件 –
谷歌圖表不需要webforms /回傳 – giammin