2012-08-16 66 views
1

大家好我有一些值...使用它们我建立我的控制器字符串i湾在我看来,页面显示的字符串....如何追加一个字符串在mvc3中查看?

这里是我的控制器代码

[ChildActionOnly] 
public ActionResult History() 
{ 
    //if(Session["DetailsID"]!=null) 
    //{ 
    int id = Convert.ToInt16(Session["BugID"]); 
     var History = GetBugHistory(id); 
     return PartialView(History); 
    //} 
    //int id1 = Convert.ToInt16(Session["BugID"]); 
    //var History1 = GetBugHistory(id1); 
    //return PartialView(History1); 

} 
/// <summary> 
///To the List of Resolutions and Employeenames Based on BugID 
/// </summary> 
/// <param>Bug Id</param> 
/// <returns>BugHistory</returns>  
public List<BugModel> GetBugHistory(int id) 
{ 

    var modelList = new List<BugModel>(); 
    using (SqlConnection conn = new SqlConnection(ConnectionString)) 
    { 
     conn.Open(); 
     SqlCommand dCmd = new SqlCommand("History", conn); 
     dCmd.CommandType = CommandType.StoredProcedure; 
     dCmd.Parameters.Add(new SqlParameter("@BugID", id)); 
     SqlDataAdapter da = new SqlDataAdapter(dCmd); 
     DataSet ds = new DataSet(); 
     da.Fill(ds); 
     StringBuilder sb = new StringBuilder(); 
     conn.Close(); 
     for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) 
     { 
      var model = new BugModel(); 
      model.FixedBy = ds.Tables[0].Rows[i]["FixedByEmployee"].ToString(); 
      model.Resolution = ds.Tables[0].Rows[i]["Resolution"].ToString(); 
      model.AssignedTo = ds.Tables[0].Rows[i]["AssignedEmployee"].ToString(); 
      model.Status = ds.Tables[0].Rows[i]["Status"].ToString(); 
      model.ToStatus= ds.Tables[0].Rows[i]["ToStatus"].ToString();     
      modelList.Add(model); 
      sb.Append("'" + model.FixedBy + "'" + "has updated the status from" + "'" + model.ToStatus + "'" + "to" + "'" + model.Status + "'" + "and Assigned to" + "'" + model.AssignedTo + "'"); 
     } 
     return modelList; 
    }   
} 

我应该如何显示使用foreach循环

回答

0

阿尼尔这串在我的局部视图页面,

我建议创建处理纯粹是的输出显示一个partialview(_BugModelList.cshtml)。这可能是这个样子:

@model IList<BugModel> 

<table> 
    <thead> 
     <tr> 
      <th>Fixed by</th> 
      <th>From Status</th> 
      <th>To Status</th> 
      <th>Assigned to</th> 
     </tr> 
    </thead>  
    @{ 
     foreach (var item in Model) 
     { 
      <tr> 
       <td>@item.FixedBy</td> 
       <td>@item.ToStatus</td> 
       <td>@item.Status</td> 
       <td>@item.AssignedTo</td> 
      </tr> 
     } 
    } 
</table> 

,或者,如果你想在一个字符串每控制器(未经测试显然)为:

@model IList<BugModel> 

@{ 
    foreach (var item in Model) 
    { 
     <p> 
      @{ "'" + item.FixedBy + "'" 
        + " has updated the status from " 
        + "'" + item.ToStatus + "'" 
        + " to " + "'" + item.Status + "'" 
        + " and Assigned to " + "'" + item.AssignedTo + "'"; } 
     </p> 
    } 
} 

这会再从你的主要观点被称为每你目前拥有的行动。很明显,我将它格式化为table,但是您可以重构它以适应逻辑保持不变。

[编辑] - 重新阅读您的问题,您可能希望将列表呈现为表格,而不是无序列表。请参阅上面的编辑

+0

以上建议的任何喜悦? – 2012-08-17 16:03:36