// Page
@ Model pagedlist. ipagedlist <taoniubbs. Models. tn_post>
@{
Viewbag. Title = "postmanage ";
Layout = "~ /Views/shared/layout. cshtml ";
}
<SCRIPT src = ".../scripts/jquery-1.5.1.js" type = "text/JavaScript"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
<! -- Begin
VaR checkflag = "false ";
Function check (field ){
If (checkflag = "false "){
For (I = 0; I <field. length; I ++ ){
Field [I]. Checked = true;
}
Checkflag = "true ";
Return "Invert selection ";
}
Else {
For (I = 0; I <field. length; I ++ ){
Field [I]. Checked = false;
}
Checkflag = "false ";
Return "select all ";
}
}
// End -->
$ (Function (){
$ ("# Deletelist"). Click (function (){
VaR innertext = "";
$ ("Input [type = 'checkbox']"). Each (function (){
If ($ (this). ATTR ("checked") = true ){
Innertext + = $ (this). siblings ("input [type = 'den den ']"). Val () + "| ";
}
});
If (innertext! = ""){
$. Post ("/post/delete? Id = "+ innertext, function (){
Alert ("deleted successfully! ");
});
}
});
})
</SCRIPT>
<H2> postmanage </H2>
<P>
@ Html. actionlink ("create new", "CREATE ")
</P>
<Form name = "myform" method = "Post">
<Table>
<Tr>
<TH>
Select
</Th>
<TH>
Post Title
</Th>
<TH>
Community
</Th>
<TH>
User Name
</Th>
<TH>
Release Date
</Th>
<TH>
Attachment
</Th>
<TH>
Post type
</Th>
<TH>
View
</Th>
<TH>
Reply
</Th>
<TH>
Last reply
</Th>
<TH>
Replied?
</Th>
<TH>
Excellent?
</Th>
<TH>
Reclaim?
</Th>
<TH>
Operation
</Th>
</Tr>
@ Foreach (VAR item in Model ){
String status = "";
If (item. Status = 1)
{
Status = "yes ";
}
Else
{
Status = "no ";
}
String iscream = "";
If (item. iscream = true)
{
Iscream = "excellent ";
}
Else
{
Iscream = "non-essential ";
}
<Tr>
<TD> <input type = "checkbox" id = "list" name = "list"/> <input type = "hidden" value = "@ item. postid "/> </TD>
<TD>
@ Item. posttitle
</TD>
<TD>
@ Item. tn_community.communityname
</TD>
<TD>
@ Item. tn_userinfo.userid
</TD>
<TD>
@ String. Format ("{0: g}", item. pubtime)
</TD>
<TD>
<A href = "@ item. postattachment"> View </a>
</TD>
<TD>
@ Item. posttype. typename
</TD>
<TD>
@ Item. Views
</TD>
<TD>
@ Item. Reply
</TD>
<TD>
@ String. Format ("{0: g}", item. lastreplytime)
</TD>
<TD>
@ Status
</TD>
<TD>
@ Iscream
</TD>
<TD>
@ Item. ismove
</TD>
<TD>
@ Html. actionlink ("change", "edit", new {id = item. postid}) |
@ Html. actionlink ("View", "details", new {id = item. postid })
</TD>
</Tr>
}
</Table>
<Input type = "button" value = "select all" onclick = "This. value = check (this. Form. List)"/>
<Input type = "Submit" id = "deletelist" value = "delete"/>
</Form>
<Div>
@ (Model. pagecount <model. pagenumber? 0: model. pagenumber)
/@ Model. pagecount
& Nbsp;
@ If (model. haspreviouspage)
{
@ Html. actionlink ("<", "postmanage", new {page = 1, currentfilter = viewbag. currentfilter })
@ Html. Raw ("& nbsp ;");
@ Html. actionlink ("<previous page", "postmanage", new {page = model. pagenumber-1, currentfilter = viewbag. currentfilter })
}
Else
{
@: <
@ Html. Raw ("& nbsp ;");
@: <Previous Page
}
& Nbsp;
@ If (model. hasnextpage)
{
@ Html. actionlink ("next page>", "postmanage", new {page = model. pagenumber + 1, currentfilter = viewbag. currentfilter })
@ Html. Raw ("& nbsp ;");
@ Html. actionlink (">", "postmanage", new {page = model. pagecount, currentfilter = viewbag. currentfilter })
}
Else
{
@: Next page>
@ Html. Raw ("& nbsp ;")
@:>
}
</Div>
Cotroller:
Public viewresult postmanage (string currentfilter, string searchstring, Int? Page)
{
If (request. httpmethod = "get ")
{
Searchstring = currentfilter;
}
Else
{
Page = 1;
}
Viewbag. currentfilter = searchstring;
VaR tn_post = dB. tn_post.where (C => C. ismove = false). orderbydescending (P => P. lastreplytime). tolist ();
If (! String. isnullorempty (searchstring ))
{
Tn_post = tn_post.where (E => E. posttitle. Contains (searchstring). tolist ();
}
Int pagesize = 10;
Int pageindex = (page ?? 1)-1;
Return view (tn_post.topagedlist (pageindex, pagesize ));
}
// Normal Deletion
Public actionresult Delete (guid ID)
{
Tn_post = dB. tn_post.find (ID );
Return view (tn_post );
}
[Httppost, actionname ("delete")]
Public actionresult deleteconfirmed (string ID)
{
If (ID! = NULL)
{
String [] STR = ID. Split ('| ');
Foreach (var I in Str)
{
If (I! = "")
{
Guid postid = guid. parse (I. tostring ());
Tn_post = dB. tn_post.find (postid );
Tn_post.ismove = true;
Updatemodel (tn_post );
DB. savechanges ();
}
Else
{
Return redirecttoaction ("Index ");
}
}
}
Else
{
Return redirecttoaction ("Index ");
}
Return redirecttoaction ("Index ");
}
Protected override void dispose (bool disposing)
{
DB. Dispose ();
Base. Dispose (disposing );
}