MVC Web grid with column with line break

Controler::
__________________________
[HttpGet]
public ActionResult EmployeeTaskReport()
{
using (DataAccessLayer.DatabaseContext db = new DataAccessLayer.DatabaseContext())
{
int UserLoginID = UserRepository.GetLoginUserID();
var UserTaskList = db.TaskMasters.Where(_ => _.LoginID.Value.Equals(UserLoginID)).ToList();
ViewBag.TaskStatus = db.TaskStatusMasters.ToList();
ViewBag.SchoolName = db.SchoolMasters.ToList();
ViewBag.ProjectName = db.ProjectMasters.ToList();
//return View(UserTaskList);

List lstERTVM = new List();
foreach (TaskMaster tm in UserTaskList)
{
lstERTVM.Add(new EmployeeTaskReportViewModel { TMaster = tm });
}
return View(lstERTVM);

}
}

ViewModel____________________________
public class EmployeeTaskReportViewModel
{
public TaskMaster TMaster { get; set; }

public string TaskReportDetail;

public string _TaskReportDetail
{
get {
TaskReportDetail += “TaskName: ” + Convert.ToString(this.TMaster.TaskName) + “\r\n”;
TaskReportDetail += “SchoolName: ” + (this.TMaster.SchoolMaster == null ? “” : Convert.ToString(this.TMaster.SchoolMaster.SchoolName)) + “\r\n”;
TaskReportDetail += “ProjectName: ” + (this.TMaster.ProjectMaster == null ? “” : Convert.ToString(this.TMaster.ProjectMaster.ProjectName)) + “\r\n”;
return TaskReportDetail;
}
set { TaskReportDetail = value; }
}

}
Web grid in View______________

@{
WebGrid grid = new WebGrid(Model);
@grid.GetHtml(
tableStyle: “grid”,
fillEmptyRows: false,
headerStyle: “gvHeading”,
alternatingRowStyle: “gvAlternateRow”,
rowStyle: “gvRow”,
footerStyle: “gvFooter”,

mode: WebGridPagerModes.All,
firstText: “<< First",
previousText: "”,
lastText: “Last >>”,
columns: new[] {

grid.Column(“Sr.No.”, format: item => item.WebGrid.Rows.IndexOf(item)+1),
grid.Column(“Review”, format: (item) =>
{
string review = item._TaskReportDetail ?? “”;
return new HtmlString(review.Replace(“\r\n”, “
“));
}),

grid.Column(“ContactusId”, header: “Action”, canSort:false,

format: @

)
})
}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s