文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>WebMatrix轻量级web开发Razor的一个小demo

WebMatrix轻量级web开发Razor的一个小demo

时间:2011-05-22  来源:风云8

@{
    if(IsPost)
    {
        var contentx = Request.Form["contentx"];
        var userName = Request.Form["username"];
        var conment = new Content {
            content = contentx,
        userName=userName,
        addTime=DateTime.Now,
        guid=Guid.NewGuid()
        };
        if (Request.Form["parentid"] != "")
        {
            conment.pid = new Guid(Request.Form["parentid"]);
        }
       
    var list = Context.Application["list"] as List<Content>;
    if(list==null)
    {
        list = new List<Content>();
        Context.Application["list"] = list;
    }
      list.Add(conment);
      Response.Redirect("Index.cshtml");
    }
  
   
   
 
   
    }


<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <ul>
        @{
            var allist=(Context.Application["list"] as List<Content>)??new List<Content>();
            }
          
                @foreach(var item in allist)
                {
                    <li>
                    内容:@item.content<br />
                    发布人:@item.userName @@
                    @item.addTime.ToString("MM:dd: HH:mm:ss") <br />
                    <a href="[email protected]">回复</a>
                    </li>
                    if (item.pid != null)
                    {
                        <ul>
                         @foreach(var it in allist.Where(r=>r.pid==item.guid))
                         {
                         <li>
                          @it.content
                         </li>
                         }
                        </ul>
                    }
               
                }
           
       
       
        </ul>

        <form action="" method="post">
        <input type="hidden" value="@Request.QueryString["id"]" name="parentid" />
        <label title="">留言内容:</label><textarea name="contentx"></textarea>
        <label title="">用户名</label><input type="text" name="username" />
        <input type="submit" value="提交" />

       
        </form>
    </body>
</html>

 

对象:Content

 

public class Content
{
    public Content()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public Guid guid { get; set; }
    public string userName { get; set; }
    public string content { get; set; }
    public DateTime addTime { get; set; }
    public Guid? pid { get; set; }

   
}

 

相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载