HI all i have some values…using them i am building a string in my controller i wan to display the string in my view page….
here is my controller code
[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;
}
}
How should i show this string in my partial view page using a foreach loop
anil,
I’d suggest creating a partialview (_BugModelList.cshtml) that handles purely the output display of the
BugModel. This may look something like this:or, if you wanted the single string as per your controller (untested obviously):
this would then be called from your main view as per the action that you presently have. Obviously, I’ve formatted it as
tablebut you can refactor that to suit, the logic remains the same.[Edit] – re-reading your question, you probably want to present the list as a table, rather than as an unordered list. See edit above