此时我希望文本区域为空,因为我已将ViewData ["SomeText"]设置为string.Empty
为什么在发布操作后文本区域值不会更新为空字符串?
以下是行动:
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Message(int ID)
{
ViewData["ID"] = ID;
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Message(int ID, string SomeText)
{
// save Text to database
SaveToDB(ID, SomeText);
// set the value of SomeText to empty and return to view
ViewData["SomeText"] = string.Empty;
return View();
}
Run Code Online (Sandbox Code Playgroud)
和相应的观点:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<% using (Html.BeginForm())
{ %>
<%= Html.Hidden("ID", ViewData["ID"])%>
<label for="SomeText">SomeText:</label>
<%= Html.TextArea("SomeText", ViewData["SomeText"]) …Run Code Online (Sandbox Code Playgroud) 我们可以在控制器和视图中访问会话数据,如下所示:
Session["SessionKey1"]
Run Code Online (Sandbox Code Playgroud)
如何从控制器或视图以外的类访问会话值?
我试图在包装DIV(纯绿色边框)内包含两个DIV元素,内部1和内部2(点缀红色边框),但包装器DIV元素不会展开以包围内部DIV.
我究竟做错了什么?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> Nested divs </title>
</head>
<body>
<div id="wrapper" style="margin-left:auto; margin-right:auto; border:solid #669933;">
content inside "wrapper" div
<div id="inner-1" style="float:left; width:49%; border:dotted #CC3300;">
content <br />
inside <br />
inner-1 div
</div>
<div id="inner-2" style="float:left; width:49%; border:dotted #CC3300;">
content inside inner-2 div
</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我有一个CustomeAuthorize操作过滤器,如果用户未经过身份验证,则会将用户转发到登录页面.我将此过滤器应用于操作或控制器.
[CustumeAuthorize]
public ActionResult MyAction()
{
//do something here
return View();
}
Run Code Online (Sandbox Code Playgroud)
过滤器看起来像这样:
public class CustomAuthorizeAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (!currentUserIsAuthenticated)
{
filterContext.Result =
new RedirectToRouteResult(
new RouteValueDictionary{{ "controller", "Account" },
{ "action", "SignIn" },
{ "returnUrl", filterContext.HttpContext.Request.RawUrl }
});
}
else
{
base.OnActionExecuting(filterContext);
}
}
}
Run Code Online (Sandbox Code Playgroud)
一旦我为filterContext.Result分配了一个值,在执行过滤器完成后,执行(不知何故?!)重定向到SignIn操作,MyAction不执行.这正是我想要的.
现在说我想改变我的CustomAuthorize来对外部网站进行身份验证,而不是我自己的SignIn操作,所以我这样做:
public class CustomAuthorizeAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (!currentUserIsAuthenticated)
{
filterContext.HttpContext.Response.Redirect("http://externalSite.com/login?returnUrl=" + filterContext.HttpContext.Request.RawUrl);
}
else
{
base.OnActionExecuting(filterContext);
}
}
} …Run Code Online (Sandbox Code Playgroud) 我正在寻找一个开源的C#库,具有灵活的许可,可以在ASP.NET MVC应用程序中使用.
它应该能够根据本地数据库,facebook,twitter,OpenID或其他流行的身份验证方法对用户进行身份验证.
有这样的图书馆吗?
我有一个在ASP.NET MVC(V 1.0)上编写的应用程序.该应用程序在IIS7上运行,DNS由GoDaddy提供.
我想将来自http://mydomain.com/ctrlr/act/value的任何请求转发到此表单的网址:http://WWW.mydomain.com/ctrlr/act/value
基本上,如果有人试图访问http://mydomain.com,我想将WWW添加到主机名
最好的方法是什么?
我有一个在IIS7上运行的ASP.NET MVC应用程序.我使用会话来跟踪登录用户.有一个名为IsSignedIn的会话.("true"表示此用户当前已登录).
我还有一个应用程序的管理页面.
现在,说已登录的user1必须立即暂停使用该服务.所以我想从我的管理页面中为user1设置的会话变量无效(这将强制用户再次登录).
有没有办法可以从我的管理页面访问/修改每个登录用户设置的会话变量?
我在不同的控制器中有动作,需要在执行前检查一些条件.如果不满足条件,我希望将用户重定向到另一个页面,其中包含有关下一步操作的说明(说明将包含用户必须遵循的链接).
例如,SendMessage()操作位于Message控制器中:
public ActionResult SendMessage()
{
// check if user has enough credit
if (!hasEnoughCredit(currentUser))
{
// redirect to another page that says:
// "You do not have enough credit. Please go to LinkToAddCreditAction
// to add more credit."
}
// do the send message stuff here
}
Run Code Online (Sandbox Code Playgroud)
我想在Requirements控制器中有一个名为ShowRequirements()的通用操作.
在SendMessage()操作中,我想设置要向用户显示的消息,然后将用户转发到ShowRequirements()操作.我只是不希望该消息出现在ShowRequirements操作的URL中.
有没有办法将这些数据传达给ShowRequirements()动作?
asp.net-mvc ×7
c# ×3
iis ×2
session ×2
css ×1
forms ×1
html ×1
open-source ×1
redirect ×1
xhtml ×1