MVC 2 - Name Attributes on HTML Input Field when using Parent/Child Entities

Posted by Click Ahead on Stack Overflow See other posts from Stack Overflow or by Click Ahead
Published on 2010-04-21T01:08:27Z Indexed on 2010/04/21 1:13 UTC
Read the original article Hit count: 263

Hi All,

I'm pretty new to MVC 2 using the Entity Framework. I have two tables Company {ID int identity PK,Name nvarchar} and User {ID int identity PK,UserName nvarchar,CompanyID int FK}. A Foreign Key exists between User and Company.

I generated my ADO.NET Entity Data Model, a Controller and a view to insert a record. My HTML form has the fields Company and UserName and the idea is when I click save a Company and User is inserted into the database. Sounds straight forward right!

My question is as follows:
I created a strongly-typed view derived from my 'User' entity. I'm using the the html helper Html.TextBoxFor(model => model.Organisation.Name) but the html name attribute for this input field is 'Organisation.Name'. My problem with this is that the dot throws up all sorts of issues in JQuery, which sees this as a property. If I want to change the name I read that I can use DataAnnotations but because I used the Entity Designer this involves using Buddy Classes. Seems like a bit of overkill just to change the html name attribute on this input field. Am I approaching this the right way or am I missing something here?

Thanks for the help !

© Stack Overflow or respective owner

Related posts about mvc2

Related posts about html.textbox