一个usercenter.aspx页面中4个用户控件,代码如下:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Register Src="../ascx/user/userInformation.ascx" TagName="userInformation" TagPrefix="MB" %>
<%@ Register Src="../ascx/user/myShoucang.ascx" TagName="myShoucang" TagPrefix="MB" %>
<%@ Register Src="../ascx/tiezi/fatiezi.ascx" TagName="fatiezi" TagPrefix="MBB" %>
<%@ Register Src="../ascx/tiezi/tiezi_list.ascx" TagName="tz_list" TagPrefix="MBB" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
个人用户首页
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>个人首页</h2>
<table>
<tr>
<td>
<MBB:fatiezi ID="ftz1" runat="server" />
</td>
<td><MB:userInformation ID="userInformation1" runat="server" /> </td>
</tr>
<tr>
<td><MBB:tz_list ID="tzList1" runat="server" /></td>
<td><MB:myShoucang ID="myShoucang1" runat="server" /></td>
</tr>
</table>
</asp:Content>其中MBB:fatiezi用于发帖子,代码如下:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="System.Text" %>
<script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="../../Scripts/formValidator.js" type="text/javascript"></script>
<script src="../../Scripts/formValidatorRegex.js" type="text/javascript"></script>
<link href="../../Content/validator.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function() {
$.formValidator.initConfig({ formid: "fatiezi1", onerror: function(msg) { }, onsuccess: function() { return true; } });
$("#neirong").formValidator({ tipid: "tip_neirong", onshow: "请填写内容", onfocus: "请填写内容", oncorrect: "OK" }).inputValidator({ min: 1, empty: { leftempty: false, rightempty: false, emptyerror: false }, onerror: "必须填写内容" });
});
</script>
<%
int user_id = 0;
if (null != ViewData["User_id"])
{
user_id = Convert.ToInt32(ViewData["User_id"].ToString());
}
%>
<form id="fatiezi1" action="<%= Url.Action("faTiezi","Account")%>" method="post">
<table>
<tr>
<td>
<textarea rows="10" cols="60" name="neirong" id="neirong"></textarea>
<div id="tip_neirong" style="width:150px"></div>
<input name="user_id" type="hidden" value="<%= user_id %>" />
</td>
</tr>
<tr>
<td align="center"><input id="Submit1" type="submit" value="发 表" /></td>
</tr>
</table>
</form>它包括一个文本框和一个Sumbit1按钮,它的Controller代码如下:
[Authorize]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult faTiezi(MB_Tiezi myTiezi)
{
ViewData["User_id"] = Session["User_id"].ToString();
try
{
myTiezi.insert_time = DateTime.Now;
myCTiezi.insertTiezi(myTiezi);
myCTiezi.SubmitChanges();
return RedirectToAction("userCenter", "Account"); // 注意这里
}
catch (Exception eee)
{
throw eee;
}
}在usercenter.spx页面还有一个MBB:tz_list用户控件,用于显示提交成功的帖子,代码如下:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="MB.modules" %>
<%
int user_id = Convert.ToInt32(ViewData["User_id"].ToString());
CTiezi myCTiezi = new CTiezi();
var ds = myCTiezi.getTieziByUser_id(user_id);
var ds2 = (from t in ds
select new
{
t.Tz_id,
t.neirong,
t.MB_tz_leixing.leixing_name,
t.dbw_Users.TrueName
}).ToList()
%>
<table>
<tr>
<td>ID</td>
<td>姓名</td>
<td>内容</td>
</tr>
<% foreach (var xx in ds2)
{ %>
<tr>
<td><% =xx.Tz_id.ToString()%></td>
<td><% =xx.TrueName %></td>
<td><% =xx.neirong %></td>
</tr>
<%} %>
</table>因为在第一个用户名控件中提交按钮返回 return RedirectToAction("userCenter", "Account");,导致整个页面都刷新,我想只熟悉Tiezi_List页面,而其他二个用户控件不刷新,请问该怎么做???
谢谢大家
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Register Src="../ascx/user/userInformation.ascx" TagName="userInformation" TagPrefix="MB" %>
<%@ Register Src="../ascx/user/myShoucang.ascx" TagName="myShoucang" TagPrefix="MB" %>
<%@ Register Src="../ascx/tiezi/fatiezi.ascx" TagName="fatiezi" TagPrefix="MBB" %>
<%@ Register Src="../ascx/tiezi/tiezi_list.ascx" TagName="tz_list" TagPrefix="MBB" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
个人用户首页
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>个人首页</h2>
<table>
<tr>
<td>
<MBB:fatiezi ID="ftz1" runat="server" />
</td>
<td><MB:userInformation ID="userInformation1" runat="server" /> </td>
</tr>
<tr>
<td><MBB:tz_list ID="tzList1" runat="server" /></td>
<td><MB:myShoucang ID="myShoucang1" runat="server" /></td>
</tr>
</table>
</asp:Content>其中MBB:fatiezi用于发帖子,代码如下:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="System.Text" %>
<script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="../../Scripts/formValidator.js" type="text/javascript"></script>
<script src="../../Scripts/formValidatorRegex.js" type="text/javascript"></script>
<link href="../../Content/validator.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function() {
$.formValidator.initConfig({ formid: "fatiezi1", onerror: function(msg) { }, onsuccess: function() { return true; } });
$("#neirong").formValidator({ tipid: "tip_neirong", onshow: "请填写内容", onfocus: "请填写内容", oncorrect: "OK" }).inputValidator({ min: 1, empty: { leftempty: false, rightempty: false, emptyerror: false }, onerror: "必须填写内容" });
});
</script>
<%
int user_id = 0;
if (null != ViewData["User_id"])
{
user_id = Convert.ToInt32(ViewData["User_id"].ToString());
}
%>
<form id="fatiezi1" action="<%= Url.Action("faTiezi","Account")%>" method="post">
<table>
<tr>
<td>
<textarea rows="10" cols="60" name="neirong" id="neirong"></textarea>
<div id="tip_neirong" style="width:150px"></div>
<input name="user_id" type="hidden" value="<%= user_id %>" />
</td>
</tr>
<tr>
<td align="center"><input id="Submit1" type="submit" value="发 表" /></td>
</tr>
</table>
</form>它包括一个文本框和一个Sumbit1按钮,它的Controller代码如下:
[Authorize]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult faTiezi(MB_Tiezi myTiezi)
{
ViewData["User_id"] = Session["User_id"].ToString();
try
{
myTiezi.insert_time = DateTime.Now;
myCTiezi.insertTiezi(myTiezi);
myCTiezi.SubmitChanges();
return RedirectToAction("userCenter", "Account"); // 注意这里
}
catch (Exception eee)
{
throw eee;
}
}在usercenter.spx页面还有一个MBB:tz_list用户控件,用于显示提交成功的帖子,代码如下:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="MB.modules" %>
<%
int user_id = Convert.ToInt32(ViewData["User_id"].ToString());
CTiezi myCTiezi = new CTiezi();
var ds = myCTiezi.getTieziByUser_id(user_id);
var ds2 = (from t in ds
select new
{
t.Tz_id,
t.neirong,
t.MB_tz_leixing.leixing_name,
t.dbw_Users.TrueName
}).ToList()
%>
<table>
<tr>
<td>ID</td>
<td>姓名</td>
<td>内容</td>
</tr>
<% foreach (var xx in ds2)
{ %>
<tr>
<td><% =xx.Tz_id.ToString()%></td>
<td><% =xx.TrueName %></td>
<td><% =xx.neirong %></td>
</tr>
<%} %>
</table>因为在第一个用户名控件中提交按钮返回 return RedirectToAction("userCenter", "Account");,导致整个页面都刷新,我想只熟悉Tiezi_List页面,而其他二个用户控件不刷新,请问该怎么做???
谢谢大家
你试试ajax 的updatepanel 局部刷新看看
<h2>个人首页</h2>
<table>
<tr>
<td>
<% Html.RenderPartial("ascx/tiezi/fatiezi"); %>
</td>
<td><% Html.RenderPartial("ascx/user/userInformation"); %></td>
</tr>
<tr>
<td><% Html.RenderPartial("ascx/tiezi/tiezi_list"); %></td>
<td><% Html.RenderPartial("ascx/user/myShoucang"); %></td>
</tr>
</table>
</asp:Content>
调用方式我已经改过来了
动态 刷新 指定ascx控件 的好方法
代码:
view页面:
<%Html.RenderPartial("UserDetails", Session("Login_User"))%>controlers 类
Function AjaxLogin(ByVal userName As String, ByVal password As String) As ActionResult
If Not Request.IsAjaxRequest() Then
Return Content("请不要非法方法,这是不道德的行为!")
Else
Dim isUser As Boolean = False
'user
Dim userBll As WE_V_User = New WE_V_User()
Dim userVS As List(Of Model.WE_V_User) = userBll.GetModelList("userName = '" & userName & "' and password = '" & password & "'")
If userVS.Count > 0 Then
Session("Login_User") = userVS.Item(0)
End If
'company
'Return RedirectToAction("index", "home")
Return View("LoginUserControl", Nothing)
End If
End Function