MVC LINQ ViewModel Not Returnng Name Property Correctly?

The View is successfully returning all 'Limit' properties, and return the the word Name for the 'Name' property instead of actual names in the db table.

Current View Return;
Category 	Limit
Name		50 	
Name 	        40 	
Name 	       100 	

Open in new window


View output should look like this:
10/2013

October

Category 	Limit
Auto 		50 	
Clothing 	40 	
College 	100 	
Credit 		100 	
Food 		200 	

     Save Changes

Open in new window


Here is the code I have so far which doesn't work

[Models]
   
    public class BudgetViewModel
    {        
        public List<BudgetList> budgetList { get; set; }
    }

    public class BudgetList
    {
        public string Name { get; set; }
        public System.Guid BudgetID { get; set; }
        public System.Guid BudgetItemID { get; set; }
        public System.Guid CategoryID { get; set; }
        public decimal Limit { get; set; }
        public System.DateTime Date { get; set; }
        public System.DateTime Posted { get; set; }   
    }

Open in new window


[Editor Template]
@model BudgetProjectUI.BudgetList
<table>
    <tr>
        <td>@Html.LabelFor(x => x.Name)</td>
        <td></td>
        <td></td>
        <td>@Html.EditorFor(x => x.Limit)</td>
    </tr>
</table>

Open in new window


[View]
@model BudgetProjectUI.BudgetViewModel
<div style="float: left;">
           
                <div style="float: left;">

                    Month Name

                    @using (Html.BeginForm("_Edit", "Budget", FormMethod.Post))
                    {
                        <fieldset>
                            <legend> Month/Year </legend>
                            <table>
                                <thead>
                                    <tr>
                                        <td><b>Category</b></td>
                                        <td></td>
                                        <td><b>Limit</b></td>
                                    </tr>
                                </thead>
                                <tbody>
                                    
                                        @Html.EditorFor(model => model.budgetList)

                                </tbody>
                            </table>
                        </fieldset>  
                                                
                        <input type="submit" value="Save Changes" />                                
                    }
                           
            </div>

Open in new window


[Action]
 public ActionResult Budgets()
        {
            BudgetViewModel model = new BudgetViewModel
            {
                budgetList = (from b in context.Budgets
                              join r in context.CategoryRefs on b.CategoryID equals r.CategoryID
                              select new BudgetList() { Name = r.Name, Limit = b.Limit }).ToList()
            };

            return View(model);
        }

Open in new window

WorknHardrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
my best guess is that you have LabelFor:

@Html.LabelFor(x => x.Name)

Since there isn't any other attribute, it would use "Name" for the label.
0
Craig WagnerSoftware ArchitectCommented:
<td>@Html.LabelFor(x => x.Name)</td>

should be

<td>@Model.Name</td>

You don't want a label for the property you just want the value of the property.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WorknHardrAuthor Commented:
Okay, @Model.Name works.

Note: the only diff between Name and Limit is string or decimal

Q.  I don't understand why neither Html.LabelFor or Html.Label doesn't work?
0
Bob LearnedCommented:
LabelFor is intended to generate a label for a property, and in the absence of any attributes, it uses the name of the property to generate a label.
0
WorknHardrAuthor Commented:
thx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.