I have this problem:
I have a result grid with a column named Note. I want to set a static string into the column cell (e.g: Nota) if note field is full (now in this field there is the note content) else I want to display a empty cell.
This is my Controller:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(CLI_POLIZZA cli_polizza)
{
if (ModelState.IsValid)
{
var cliPolizzaManager = new CliPolizzaManager();
cli_polizza.RegistrazioneID = Guid.NewGuid();
if (cli_polizza.Tipo =="C"){
cliPolizzaManager.GetScadenza(dataScadenza,
cli_polizza.GGAnticipo);
var dataScadenza = (DateTime)cli_polizza.DataScad;
cli_polizza.DataAvviso = dataScadenza.AddDays((-1) * (double)cli_polizza.GGAnticipo);
}
db.CLI_POLIZZA.Add(cli_polizza);
db.SaveChanges();
**if (cli_polizza.Nota != null)
{
TempData["Message"] = "Nota";
}**
return RedirectToAction("Index");
}
public ActionResult Index()
{
var cli_polizza = db.CLI_POLIZZA.Include(c => c.CLIENTE).Include(c => c.POLIZZA);
ViewBag.Message = TempData["Message"];
return View(cli_polizza.ToList());
}
This is my View:
<tbody>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.CLIENTE.FullName)
</td>
...
<td>
**@Html.DisplayFor(modelItem => @ViewBag.Message)**
</td>
<td>
<button type="button" class="btn btn-dark btn-sm">@Html.ActionLink("Modifica", "Edit", new { id = item.RegistrazioneID }) </button>
<button type="button" class="btn btn-success btn-sm">@Html.ActionLink("Dettaglio", "Details", new { id = item.RegistrazioneID }) </button>
<button type="button" class="btn btn-danger btn-sm">@Html.ActionLink("Cancella", "Delete", new { id = item.RegistrazioneID }) </button>
</td>
</tr>
I can't use viewbag with redirecttoaction so I tried to use Tempdata but with No result: I'm newbie
I would like to have following result:
Can someone help me?
