public class ReverseLinkedList
{
void main()
{
Node list = InitList();
Console.WriteLine(list);
list = list.ReverseList(list);
Console.WriteLine(list);
}
public Node InitList()
{
Node head = new Node();
head.Next = null;
head.Data = -1;
Node q, p;
p = head;
for (int i = 1; i <= 10; i++)
{
q = new Node();
q.Data = i;
q.Next = null;
p.Next = q;
p = q;
}
return head;
}
}
public class Node
{
private T data;
private Node next;
public T Data
{
get { return data; }
set { this.data = value; }
}
public Node Next
{
get { return next; }
set { next = value; }
}
public Node ReverseList(Node head)
{
if (head.Next == null || head.Next.Next == null)
{
return head; /*链表为空或只有一个元素则直接返回*/
}
Node t = null,
p = head.Next,
q = head.Next.Next;
while (q != null)
{
t = q.Next;
q.Next = p;
p = q;
q = t;
}
/*此时q指向原始链表最后一个元素,也是逆转后的链表的表头元素*/
head.Next.Next = null; /*设置链表尾*/
head.Next = p; /*调整链表头*/
return head;
}
public override string ToString()
{
string result = string.Empty ;
Node p = this.Next;
while (p != null)
{
result += string.Format("{0}t", p.Data);
p = p.Next;
}
return result;
}
}
分类目录归档:后端
Html.BeginForm add class attribute
@Html.BeginForm("DoSearch", "Search", FormMethod.Post, new { @class = "myclass"})
Add/remove site map node using MvcSiteMapProvider
add new CustomSiteMapProvider
public class CustomSiteMapProvider : DefaultSiteMapProvider
{
public void ClearSiteMap()
{
Clear();
}
}
Change web.config file to use the custom sitemapprovider instead of DefaultSiteMapProvider.
When node changes, add
((CustomSiteMapProvider)SiteMap.Provider).ClearSiteMap();
.net mvc display image from file
controller:
public ActionResult Image(string id)
{
var dir = Server.MapPath("/Images");
var path = Path.Combine(dir, id + ".jpg");
return base.File(path, "image/jpeg");
}
view:
<img src="@Url.Action("Image", new { id= Model.Guid })" alt="@Model.Name" width="300" >
IIS .net upload large file congif
IIS 7.x,
?<system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="2147483648" /> </requestFiltering> </security> </system.webServer>
IIS 6.0
?<system.web> <httpRuntime maxRequestLength="2097151" /> </system.web>
nhibernate cascade delete
<bag name="FileTagRelations" table="FileTagRelation" inverse="true" cascade="delete">
<key column="FileID" foreign-key="FileID" />
<one-to-many class="Entity.FileTagRelationEntity, Entity"/>
</bag>
Using the ASP.NET MVC 3 Logon returnUrl Parameter
razor:
@{
ViewBag.Title = "登陆";
Layout = "~/Views/Shared/_LoginLayout.cshtml";
string retUrl = "";
if (Request["ReturnUrl"] != null)
{
retUrl = ViewContext.HttpContext.Request["ReturnUrl"];
}
}
@using (Html.BeginForm("Logon", "Account", new { model = this.Model, ReturnUrl = retUrl }))
{
//form
}
controller:
[HttpPost]
public ActionResult LogOn(LogOnModel model, string ReturnUrl)
{
ViewBag.UserLogOut = true;
if (!ModelState.IsValid)
return View("Logon");
if (ModelState.IsValid)
{
try
{
//login
}
catch (Exception e)
{
ModelState.AddModelError("", e.Message);
return View(model);
}
}
if (!string.IsNullOrEmpty(ReturnUrl))
return Redirect(ReturnUrl);//return
return RedirectToAction("Index", "Product");
}
UserSessionAuthorizeAttribute:
public class UserSessionAuthorizeAttribute : AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
base.OnAuthorization(filterContext);
if(//check session)
{
filterContext.Result = new RedirectToRouteResult(
new System.Web.Routing.RouteValueDictionary
{
{ "controller", "Account" },
{ "action", "LogOn" },
{ "ReturnUrl", filterContext.HttpContext.Request.RawUrl }
});
}
}
}
本地iis二级域名设置
mvc3 ajax refresh partial page
$.get('@(Url.Action("HeaderLinks", "Common" ))', function (data) {
$('#header-links-wrapper').html(data);
});
MVC3-Razor输出Html
输出HTML代码(包含标签):直接输出,
string html = "文本";
@html
输出HTML内容(不包含标签):有两种方法,
第一种:
IHtmlString html=new HtmlString("文本");
@html ;
第二种:
string html = "文本";
@Html.Raw(html);