As the subject says, DisplayNameFor is not displaying my data - However, TextboxFor does ?? Why ??
I have added My Controller(with the Method being called), Model(With a part of the properties as to not flood the page too much and so you get the idea of what my model looks like) and my View.
Your help would be greatly appreciated!
Controller:
public ActionResult ProjectInformation(ProjectDetailsViewModels model, int ProjectID)
{
if(!ModelState.IsValid)
{
return View(model);
}
var PIVM = new ProjectInformationViewModel();
using (RexusTradingEntities RTE = new RexusTradingEntities())
{
var ProjectDropDownList = (from PI in RTE.ProjectInformations.ToArray()
orderby PI.Project_Name
select new SelectListItem
{
Text = PI.Project_Name.ToString(),
Value = PI.pkiProjectID.ToString(),
Selected = true
}).ToArray();
//For DropDownList
PIVM.SelectedProjectID = ProjectID;
//Adding LIST for DropDownList
PIVM.ProjectList = ProjectDropDownList;
var ProjectData = from PIV in RTE.ProjectInformations
where PIV.pkiProjectID == ProjectID
select new
{
PIV.Designer_Name,
PIV.Project_Name,
PIV.Project_Type,
PIV.Pump_Head,
PIV.Reservoir_Start_Height,
PIV.Reservoir_Discharge_Height,
PIV.Fluid_Type,
PIV.Flow_Rate,
PIV.Filling_Velocity,
PIV.Gravitational_Acceleration,
PIV.Temperature,
PIV.Elevation_Vacuum_Pressure,
PIV.Pipe_Material,
PIV.Estimated_Pipe_Rupture,
PIV.Pipe_Absolute_Roughness,
PIV.Pipe_Absolute_Roughness_Override,
PIV.Allowable_Negative_Differential_Pressure,
PIV.Air_Valve_Maximum_Spacing,
PIV.Standardise_AirValve_Size,
PIV.Standardise_Air_Valve_Pressure_Class
};
//ProjectInformation PIV = new ProjectInformation();
foreach (var pd in ProjectData)
{
PIVM.Designer_Name = pd.Designer_Name;
PIVM.Project_Name = pd.Project_Name;
PIVM.Project_Type = pd.Project_Type;
PIVM.Pump_Head = Convert.ToDecimal(pd.Pump_Head);
PIVM.Reservoir_Start_Height = Convert.ToDecimal(pd.Reservoir_Start_Height);
PIVM.Reservoir_Discharge_Height = Convert.ToDecimal(pd.Reservoir_Discharge_Height);
PIVM.Fluid_Type = pd.Fluid_Type;
PIVM.Flow_Rate = Convert.ToDecimal(pd.Flow_Rate);
PIVM.Filling_Velocity = Convert.ToDecimal(pd.Filling_Velocity);
PIVM.Gravitational_Acceleration = Convert.ToDecimal(pd.Gravitational_Acceleration);
PIVM.Temperature = Convert.ToDecimal(pd.Temperature);
PIVM.Elevation_Vacuum_Pressure = Convert.ToDecimal(pd.Elevation_Vacuum_Pressure);
PIVM.Pipe_Material = pd.Pipe_Material;
PIVM.Estimated_Pipe_Rupture = Convert.ToDecimal(pd.Estimated_Pipe_Rupture);
PIVM.Pipe_Absolute_Roughness = Convert.ToDecimal(pd.Pipe_Absolute_Roughness);
PIVM.Pipe_Absolute_Roughness_Override = Convert.ToDecimal(pd.Pipe_Absolute_Roughness_Override);
PIVM.Allowable_Negative_Differential_Pressure = pd.Allowable_Negative_Differential_Pressure;
PIVM.Air_Valve_Maximum_Spacing = Convert.ToDecimal(pd.Air_Valve_Maximum_Spacing);
PIVM.Standardise_AirValve_Size = Convert.ToDecimal(pd.Standardise_AirValve_Size);
PIVM.Standardise_Air_Valve_Pressure_Class = Convert.ToDecimal(pd.Standardise_Air_Valve_Pressure_Class);
}
//PIVM.fkUserID =
//PIVM.DateTimeStamp = DateTime.Now;
}
return View(PIVM);
}
My Model :
Model:
public class ProjectInformationViewModel
{
[Key]
public int pkiProjectID { get; set; }
//Basic Information
[Required]
[Display(Name = "Designer Name:")]
public string Designer_Name { get; set; }
[Required]
[Display(Name = "Project Name:")]
public string Project_Name { get; set; }
[Required]
[Display(Name = "Project Type:")]
public string Project_Type { get; set; }
}
My view is below :
View:
@model AirFlo_Size_Programme.Models.ProjectInformationViewModel
@{
ViewBag.Title = "Project Information";
Layout = "~/Views/Shared/_Layout.cshtml";
//SelectListItem[] DesignerList = ViewBag.DesignerList;
SelectListItem[] ProjectList = ViewBag.ProjectList;
}
<h2 style="text-align:center">@ViewBag.Title</h2>
@Html.AntiForgeryToken()
<p>
@Html.ActionLink("Create New", "Create")
</p>
@using (Html.BeginForm("ProjectInformation", "ProjectInformation"))
{
<div>
<hr />
<h4 style="font-style:italic">Basic Information</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(m => m.Project_Name)
</dt>
<dt>
@Html.DisplayNameFor(m => m.Designer_Name)
@Html.TextBoxFor(m => m.Designer_Name, new { @class = "form-control", @disabled = "true" })
</dt>
<dt>
@Html.DisplayNameFor(m => m.Project_Type)
</dt>
<dt>
@Html.DisplayNameFor(m => m.Pump_Head)
</dt>
<dt>
@Html.DisplayNameFor(m => m.Reservoir_Start_Height)
</dt>
<dt>
@Html.DisplayNameFor(m => m.Reservoir_Discharge_Height)
</dt>
<dt>
@Html.DisplayNameFor(model => model.Fluid_Type)
</dt>
<dt>
@Html.DisplayNameFor(model => model.Flow_Rate)
</dt>
<dt>
@Html.DisplayNameFor(model => model.Filling_Velocity)
</dt>
<dt>
@Html.DisplayNameFor(model => model.Gravitational_Acceleration)
</dt>
<dt>
@Html.DisplayNameFor(model => model.Temperature)
</dt>
<dt>
@Html.DisplayNameFor(model => model.Elevation_Vacuum_Pressure)
</dt>
<dt>
@Html.DisplayNameFor(model => model.Pipe_Material)
</dt>
<dt>
@Html.DisplayNameFor(model => model.Estimated_Pipe_Rupture)
</dt>
<dt>
@Html.DisplayNameFor(model => model.Pipe_Absolute_Roughness)
</dt>
<dt>
@Html.DisplayNameFor(model => model.Pipe_Absolute_Roughness_Override)
</dt>
<dt>
@Html.DisplayNameFor(model => model.Allowable_Negative_Differential_Pressure)
</dt>
<dt>
@Html.DisplayNameFor(model => model.Air_Valve_Maximum_Spacing)
</dt>
<dt>
@Html.DisplayNameFor(model => model.Standardise_AirValve_Size)
</dt>
<dt>
@Html.DisplayNameFor(model => model.Standardise_Air_Valve_Pressure_Class)
</dt>
</dl>
</div>
}
<p>
@Html.ActionLink("Edit", "Edit", new { id = Model.pkiProjectID }) |
@Html.ActionLink("Back to List", "Index")
</p>