0

This is my first MVC project, and I am having trouble getting my view page to display a variable value from my model that is passed to the view by my controller. The value is being set properly in the controller, and the model being passed to the view contains the correct data when viewing in debug. But the view only displays the name of the variable and not the value. I'm really stuck. Here is my relevant code:

Model:

namespace namespace.Models
{
    public class LatestRunInfoModel
    {
        public string LastRunDate { get; set; }
    }
}

Helper Class:

public static class Helpers
        {
            public static string GetLastRunInfo()
            {
                _OracleConnectionString = dbConnect.OraCianbroC9i_ConnectionString;
                using (OracleDataAdapter b = new OracleDataAdapter("ME.Namespace.Function", _OracleConnectionString))
                {
                    b.SelectCommand.Parameters.Add(new OracleParameter("pResults", OracleDbType.RefCursor)).Direction = ParameterDirection.Output;
                    DataTable tbl1 = new DataTable();
                    b.SelectCommand.CommandType = CommandType.StoredProcedure;
                    try
                    {
                        b.Fill(tbl1);
                        string rundate = tbl1.Rows[0]["LAST_RUN_DATE"].ToString();
                        string runby = tbl1.Rows[0]["LAST_RUN_USER"].ToString();
                        return rundate.ToString();
                    }
                    finally
                    { }
                }
            }
        }

Controller Action that sets the variable:

 public ActionResult About()
        {
            ViewBag.Message = "Message";


            xxx.HLP_Vitality.BLL.myfunction("XXXXX", 18, 2016, true);


            LatestRunInfoModel myViewModel = new LatestRunInfoModel();
            myViewModel.LastRunDate = company.xxxx.BLL.Helpers.GetLastRunInfo();


            return View(myViewModel);
        }

View and the attempt to display variable value:

 <td><label id="lblfdhdr">File Destination: </label>@Html.LabelFor(m => Model.LastRunDate)</td>

Hopefully somebody can help, I feel like I am really close just need that little push.

Edit: I had to remove some personal info and stuff like that. Ignore the names of things, it's just the display code on my view that is not working. Thanks in advance!

Acadia
  • 3
  • 3
  • `LabelFor()` displays the name of the property, not its value. If you want to display the value, use `@Html.DisplayFor()` (note that a ` –  May 04 '16 at 13:01

1 Answers1

2

LabelFor() displays the name of the property not the value should be use @Html.DisplayFor()

more check this link please

Why should I use LabelFor in MVC?

And

When should I use Html.Displayfor in MVC

Community
  • 1
  • 1
Nazmul Hasan
  • 10,130
  • 7
  • 50
  • 73
  • hmmm... I actually just got this working (miraculously) by using "ValueFor". That was the only thing I needed to change. In the process, I learned exactly what you just said. I suppose both ValueFor and DisplayFor would work? Thanks for the answer. – Acadia May 04 '16 at 13:21
  • Ok, I see what you mean. DisplayFor deals with formatting as well. – Acadia May 04 '16 at 13:24
  • yes, you are right DisplayFor deals with formatting as well – Nazmul Hasan May 04 '16 at 13:28
  • You should only use ValueFor if you are building your own HTML helper extensions , if you get your expect answer please mark this answered – Nazmul Hasan May 04 '16 at 13:38