KeelRisk
KeelRisk

Reputation: 749

linq to sql with stored procedure how to change display(UI) column name

I have an ASP.Net MVC app using LINQ to SQL with a Stored Procedure. I used the Visual Studio Object Relation Designer to create my model class. Below is code of one of the properies. I want the name of my Grid(UI) to dispay 'Units Included' as the column header, with the space and no quotes. I don't want the underscore. Do you know how I can do this? I have tried different attributes but can't get one to work.

Thanks

[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_additional_valid_units", DbType = "NChar(30)")]        
    public string Units_Included
    {
        get
        {
            return this._additional_valid_units;
        }
        set
        {
            if ((this._additional_valid_units != value))
            {
                this._additional_valid_units = value;
            }
        }
    }

Here is my .cshtml

@model HE.Web.Models.HuntDataOverview        

@{
    ViewBag.Title = "HD";
    Layout = "~/Views/SubTabOverview/_Criteria.cshtml";
}


@{          
    var grid = new WebGrid(Model.Results); 
 }  


 @using (Html.BeginForm()) 
 {        
     <div id="grid">          
        @grid.GetHtml()      
     </div>  
 } 

This is from my controller:

 public ActionResult Results(OverviewSearchCriteria criteria)
    {
        StatisticsServices services = new StatisticsServices();            
        List<GetGMUOverviewResult> re = services.GetGMUOverview(criteria);

        HDOverview combine = new HDOverview();
        combine.Results = re;            

        return View(combine);
    }

Upvotes: 0

Views: 1216

Answers (2)

KeelRisk
KeelRisk

Reputation: 749

I didn't necessarily find the answer but I have a simple work around. First of all, the best research I could find indicated that this might be a .net bug, maybe. However, to change the name of my webGrid all I need to do is not take the defaults from the model. I did that by changing my webGrid as follows:

<div id="grid">

    @grid.GetHtml( 
    tableStyle: "grid", 
    headerStyle: "head", 
    alternatingRowStyle: "alt", 
    columns: grid.Columns( 
        grid.Column("GMU","THIS IS A TEST"),
          grid.Column("Units_Included"),
          grid.Column("min_req_res_points") 
    ) 
) 

 </div>

As you will notice that the first Column, I added the new column name "THIS IS A TEST". Now I can name my columns whatever I need. FIXED!

Upvotes: 0

sarvesh
sarvesh

Reputation: 2743

Add the DisplayNameAttribute to your property and it should work assuming you are using an helper that takes ViewModelMetaData into account.

[DisplayName("Units Included")]
public string Units_Included
{
}

Upvotes: 1

Related Questions