0

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:

enter image description here

Can someone help me?

1 Answer 1

0

Try this:

@Model.Note==null? “Note”: Model.Note
Sign up to request clarification or add additional context in comments.

1 Comment

With your statement VS returns me this error: Error 1 'System.Collections.Generic.IEnumerable<PolizzeManager.Models.CLI_POLIZZA>' does not contain a definition for 'Nota' and no extension method 'Nota' accepting a first argument of type 'System.Collections.Generic.IEnumerable<PolizzeManager.Models.CLI_POLIZZA>' could be found (are you missing a using directive or an assembly reference?) If I use item.Nota (instead of Model.Nota) project builds but in my Note column I see " ==null ? “Note”: Model.Note" instead of "Nota" or blanc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.