I am having a problem displaying different text based on the result I get from my controller.
Column command_status_codeis returning value between 0 to 12 from the table. However, I would like to display different text based on the values I get from the controller.
i.e if I get 0 I would like to display Verify and if I get 1 I would like to display Active and so on.
I am not sure if I add the check in the view or do the conversion in the controller itself.
Here is the relevant code:
View
@model List<Models.AuditLogs>
<table>
<tr>
<th>User</th>
<th>Command Status Code</th>
</tr>
@foreach (var AuditLogsDetail in Model)
{
<tr>
<td>@AuditLogsDetail.user_id</td>
<td>@AuditLogsDetail.command_status_code</td>
</tr>
}
</table>
Controller
public ActionResult AuditLogs() {
string connectionstring = "MY_CONNECTION_STRING";
string sql = "select * from table_name";
SqlConnection conn = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand(sql, conn);
var Details = new List < AuditLogs > (); {
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read()) {
var AuditLogsDetail = new AuditLogs {
user_id = rdr["user_id"].ToString(),
command_status_code = rdr["command_status_code"].ToString(),
};
Details.Add(AuditLogsDetail);
}
}
return View(Details);
}
Model
public class AuditLogs
{
public string user_id { get; set; }
public string command_status_code { get; set; }
}
}
stringinstead