MVC3.0----Finishing One

Source: Internet
Author: User

1.ViewBag objects are dynamically resolved objects
@{     "Insert";}

Not only can you bind a single object to a viewbag, but you can also bind a list directly

Viewbag.category = db. Category.tolist (); A select is generated directly below

 <Selectname= "Search-sort"ID= "Sel_category">        <optionvalue="">--Please choose--</option>@foreach (var item in viewbag.category) {<optionvalue= "@item. Cid ">@item. CategoryName</option>        }     </Select>
2. Screen entity class object delivery

@model BlogMVC.Models.DataInfo

How to use @Model. Title, where title is the field of the Datainfo class

3. Direct output of HTML source code

@ (New htmlstring (Server.urldecode (model.content)))

4.jquery use of a single value pass
string " {\ "b\": \""\ "} " return JSON;

Call on the screen:

$.ajax ({type:"POST", URL:"/ajaxaction/insertblog", data: {title:title, Tag:tag, Category:category, mcontent:mcontent}, DataType:"Text", Async:true, Beforesend:function () {                //alert ("Beforesend");}, Success:function(d) {//alert ("succeed");                varJsons = eval ("(" + D + ")"); if(jsons.b > 0) {alert ("Submit Success"); } Else{alert ("Commit Failed"); }            }        });

5.jquery use of the DataTable data set screen display
 Public stringSearchAction (stringKeywordsintpageindex=1)        {            stringJSON =""; Sqlparameter[]parms=Newsqlparameter[]{NewSqlParameter ("@keywords", keywords),NewSqlParameter ("@pageIndex", PageIndex),NewSqlParameter ("@pageSize",Ten)            }; DataTable DT= Sqlhelper.gettable ("Usp_getdatamanager", parms); Dictionary<string,Object> dict =Newdictionary<string,Object>(); if(dt!=NULL&&dt. Rows.Count >0)          {              intCount = (int) Sqlhelper.executescalar ("Usp_getdatacountmanager",NewSqlparameter[] {NewSqlParameter ("@keywords", Keywords)}); stringJsondata =jsonconvert.serializeobject (DT); Dict. ADD ("Jsondata", Jsondata); Dict. ADD ("Datacount", Count); JSON=Jsonconvert.serializeobject (dict); }          Else          {              stringJsondata =jsonconvert.serializeobject (DT); Dict. ADD ("Jsondata",""); Dict. ADD ("Datacount", -1); JSON=Jsonconvert.serializeobject (dict); }                       returnJSON; }

The call on the screen:

functionajaxqueryfunc (keywords, pageindex) {$.ajax ({type:"POST", data: {keywords:keywords, Pageindex:pageindex, type:"SC"}, URL:"/ajaxaction/search", DataType:"Text", Beforesend:function () {                //Delete from line 2nd to the end of TR                varHeadr = $ ("#tab_data TR"). First (); $("#tab_data"). Children (). remove (); $("#tab_data"). Append (Headr); }, Success:function(d) {varJsons = eval ("(" + D + ")"); varDatacount = jsons["Datacount"]; if(Datacount > 0) {showpagingdiv (Datacount, pageindex); varJsondata = jsons["Jsondata"]; vardata =eval (jsondata); varSTRTR = "";  for(CCinchdata) {                        if(typeof(DATA[CC]) = = ' object ') {STRTR= Strtr + "<tr>"; STRTR= Strtr + "<td class= ' TC ' ><input name= ' ck_dataid ' value= '" + data[cc][' dataid '] + "' type= ' checkbox ' ></td& gt; "; STRTR= Strtr + "<td class= ' TC ' ><input class= ' common-input sort-input ' name= ' ord[] ' value= '" + data[cc][' Sequence '] + " ' type= ' text ' ></td> '; STRTR= Strtr + "<td>" + data[cc][' dataid "+" </td> "; STRTR= Strtr + "<td><a target= ' _blank ' href= '/blog/detail/" + data[cc][' dataid '] + "' title= '" + data[cc][' title ' + " ' > ' + data[cc][' Title ' + ' </a></td> '; STRTR= Strtr + "<td>" + data[cc][' click ' + "</td>"; STRTR= Strtr + "<td>" + data[cc][' Author "+" </td> "; STRTR= Strtr + "<td>" + "2014-03-15 21:11:01" + "</td>"; STRTR= Strtr + "<td>" + data[cc][' Tags ' + "</td>"; STRTR= Strtr + "<td><span class= ' Sp_link ' onclick=\" Sp_link_edit_click (this); \ "> Modify rank </span> &nbsp; <span class= ' sp_link ' onclick=\ "Sp_link_delete_click (this); \" > Delete </span> &nbsp; <div class= ' div_mess ' ></div></td> "; STRTR= Strtr + "</tr>"; }                    }                    $("#tab_data"). Append (STRTR); }                Else{alert ("No data Retrieved");    }            }        }); }

MVC3.0----Finishing One

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.