partialview 用法

using  MvcApplication1.Models;

@model MvcApplication1.Models.UserInfoModel

@{     ViewBag.Title = "Index";     Layout = "~/Views/Shared/Admin.cshtml"; }

<h2>Index</h2>

@*@Html.Partial("UserListPartial")

@Html.Partial("UserListPartial",1)*@

@Html.Partial("UserListPartial",@Model.UserList) @*

@Html.RenderPartial("UserListPartial")*@

@{         //用html.Partial调用的后台代码         

    //public ActionResult Index()     

    //{         //    TestMVC.Msg.UserDB userdb = new TestMVC.Msg.UserDB(ConfigurationManager.ConnectionStrings["TestMvcConnectionString"].ToString());      

   //    UserInfoModel userInfoModel = new UserInfoModel();

        //    userInfoModel.UserList = new List<Models.UserDetail>();   

      //    DataSet ds = userdb.GetAll();    

     //    if (ds != null && ds.Tables[0].Rows.Count > 0)       

  //    {         //        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)        

//        {         //            Models.UserDetail userDetail = new Models.UserDetail();        

//            userDetail.UserID = ds.Tables[0].Rows[i]["UserID"].ToString();        

//            userDetail.UserName = ds.Tables[0].Rows[i]["UserName"].ToString();        

//            userDetail.Sex = ds.Tables[0].Rows[i]["Sex"].ToString();        

//            userDetail.BirthDay = ds.Tables[0].Rows[i]["BirthDay"].ToString();        

//            userDetail.Emalil = ds.Tables[0].Rows[i]["Emalil"].ToString();        

//            userDetail.Addr1 = ds.Tables[0].Rows[i]["Addr1"].ToString();       

  //            userDetail.Addr2 = ds.Tables[0].Rows[i]["Addr2"].ToString();        

//            userInfoModel.UserList.Add(userDetail);         //        }

    //    }

  //    return View(userInfoModel);         //}

        //public ActionResult UserListPartial()  

       //{         //    return PartialView();         //}

   }

 

 

@*    服务器端代码 ,用action的调用方法

@Html.Action("NonCameraImagePartialView")

@{Html.RenderAction("NonCameraImagePartialView", new { notIntNo =1 });}

   public ActionResult NonCameraImagePartialView(int notIntNo)  

       {             NonCameraImageModel model = new NonCameraImageModel();     

          model.NotIntNo = notIntNo;       

          model.ImageUrls = GetNonCameraImage(notIntNo);

          return PartialView("NonCameraImagePartialView",model);       

  }

*@

 

@*UserListPartial.cshtml 视图*@

@*@model int

@model MvcApplication1.Models.UserDetail*@

@model IEnumerable<MvcApplication1.Models.UserDetail>

<h2>partialveiw</h2>

@*<h2>@Model</h2>*@

<table>  

   @foreach(var item in Model)  

   {                 <tr>            

                 <td>@item.UserID</td>            

                <td>@item.UserName</td>       

                </tr>    

      } </table>

posted on 2018-03-10 10:28  sxjljj  阅读(238)  评论(0编辑  收藏  举报