Using ASP.NET MVC 2 to display joined record
صفحه اصلي

Using ASP.NET MVC 2 to display joined record



I'm building out a simple simple ASP.NET MVC 2 page. Was able to do the Edit page the way I want, but am having some trouble with the Index page.

I have a table tblContacts that is joined by another table tblStates, database is normalized so the contact table (name, phone, address, city, etc) has a StateId which references a tblStates lookup table which consists of tblStates.Id and tblStates.Name.

Using Linq-To-Sql at this point... I have the Index page showing currently:

public ActionResult Index() { return View(_repository.ListAll()); } 

While we have the contacts data in its glory, am not sure how do I display the tblState.Name in the view?

<%: item.StateID %>  <-- how shall I change this into tblState.Name? 

In the Edit form I was able to display the tblStates.Name by doing this:

<%: Html.DropDownList("States", (IEnumerable<SelectListItem>)ViewData["StateID"])%> 

How do I do something like the above and display the label the 'right' way? I know there's something simple and there's a keyword/sample that I'm not finding. All the code samples I've found are telling me how to find child records and loop through it. Looked at SingleOrDefault(..), FirstOrDefault(..) and it doesn't seem right.

Thanks.


Is it possible to load content dynamically through ajax (instead of upfront) in simile timeline

1:

Error when Saving into SQL Server
If the association between tblContacts and tblStates is properly set in L2S you should be able to did the following:. ASP.NET MVC iframe load
public ActionResult Index() { return View( _repository.tblContacts ); } 
and then. ASP.NET ActionFilters and inheritance
<%: item.tblState.Name %> 
Constructing controller action URL within JQuery AJAX callImplementing JQuery UI 1.8.2 custom themes in ASP.Net MVC2

2:

How can I ensure a dynamically-generated javascript file is never cached?
Sorry for the delay, sidetracked with another projects. Asp.net thread question . Anyway, the above proposed quick fix didn't work. Went with EF4 and used a partial class to extend the tblContacts to return the State's Name... let me know if you want more info..


50 out of 100 based on 10 user ratings 730 reviews

^