Click here to Skip to main content
15,881,882 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionAutoMapper/ Web API Pin
TheOnlyRealTodd22-Jul-16 17:03
professionalTheOnlyRealTodd22-Jul-16 17:03 
AnswerRe: AutoMapper/ Web API Pin
Richard Deeming24-Jul-16 22:54
mveRichard Deeming24-Jul-16 22:54 
QuestionThe use of two drop down list Pin
Member 1264803721-Jul-16 21:25
Member 1264803721-Jul-16 21:25 
AnswerRe: The use of two drop down list Pin
Richard MacCutchan21-Jul-16 21:53
mveRichard MacCutchan21-Jul-16 21:53 
AnswerRe: The use of two drop down list Pin
F-ES Sitecore21-Jul-16 22:33
professionalF-ES Sitecore21-Jul-16 22:33 
QuestionHOW to Use DROOLS with Dotnet MVC Pin
Member 616257721-Jul-16 1:51
Member 616257721-Jul-16 1:51 
AnswerRe: HOW to Use DROOLS with Dotnet MVC Pin
F-ES Sitecore21-Jul-16 4:00
professionalF-ES Sitecore21-Jul-16 4:00 
QuestionMVC Controller Question Pin
TheOnlyRealTodd19-Jul-16 18:19
professionalTheOnlyRealTodd19-Jul-16 18:19 
I've spent many, many hours toiling through learning ASP.NET MVC. The good news is, I actually understand most of it. However, there's one thing I'm not making a connection on.

I have a simple view called Customers which just shows a table with customer names and their membership types. I discovered that in the CustomerController, if I do not put this line of code in (in bold), my view cannot access the Membershiptype.Name field:

C#
public ViewResult Index()
        {
            //Without the Include method below, the MembershipType would be null when the page loads, causing an error.
            var customers = _context.Customers.Include(c => c.MembershipType).ToList(); 
            
            return View(customers);
        }


However, I don't have to put a specific Include() in there to access customer.Name. See Customer View code below:

C#
@foreach (var customer in Model)
        {
            <tr>
                <td>@Html.ActionLink(customer.Name, "Details", "Customers", new {id = customer.Id}, null)</td>


<td>@customer.MembershipType.Name</td>
          </tr>
      }


In this example, I had to add the
C#
Include(c => c.MembershipType).
into the chain to access customer.MembershipType.Name from within the View, but there is not a
C#
Include(c => c.Name)
needed in order to access customer.Name. Why is this? What exactly is this Include method doing? Thanks.
AnswerRe: MVC Controller Question Pin
F-ES Sitecore20-Jul-16 0:13
professionalF-ES Sitecore20-Jul-16 0:13 
GeneralRe: MVC Controller Question Pin
TheOnlyRealTodd22-Jul-16 16:57
professionalTheOnlyRealTodd22-Jul-16 16:57 
QuestionMVC Model Binding Pin
MadDashCoder19-Jul-16 6:31
MadDashCoder19-Jul-16 6:31 
AnswerRe: MVC Model Binding Pin
Richard Deeming19-Jul-16 8:01
mveRichard Deeming19-Jul-16 8:01 
GeneralRe: MVC Model Binding Pin
MadDashCoder19-Jul-16 19:47
MadDashCoder19-Jul-16 19:47 
AnswerRe: MVC Model Binding Pin
F-ES Sitecore20-Jul-16 0:01
professionalF-ES Sitecore20-Jul-16 0:01 
GeneralRe: MVC Model Binding Pin
MadDashCoder20-Jul-16 7:12
MadDashCoder20-Jul-16 7:12 
GeneralRe: MVC Model Binding Pin
F-ES Sitecore20-Jul-16 22:10
professionalF-ES Sitecore20-Jul-16 22:10 
AnswerRe: MVC Model Binding Pin
jkirkerx3-Aug-16 8:01
professionaljkirkerx3-Aug-16 8:01 
QuestionMessage Closed Pin
18-Jul-16 14:50
MadDashCoder18-Jul-16 14:50 
AnswerRe: Switching From Textbox To Dropdownlistbox Pin
Richard Deeming19-Jul-16 2:04
mveRichard Deeming19-Jul-16 2:04 
Questionasp.net Pin
Member 1263882918-Jul-16 5:41
Member 1263882918-Jul-16 5:41 
QuestionRe: asp.net Pin
ZurdoDev18-Jul-16 5:58
professionalZurdoDev18-Jul-16 5:58 
AnswerRe: asp.net Pin
jkirkerx3-Aug-16 8:11
professionaljkirkerx3-Aug-16 8:11 
QuestionSetup for a web application Pin
Member 1027267614-Jul-16 3:11
professionalMember 1027267614-Jul-16 3:11 
AnswerRe: Setup for a web application Pin
koolprasad200314-Jul-16 18:30
professionalkoolprasad200314-Jul-16 18:30 
AnswerRe: Setup for a web application Pin
John C Rayan18-Jul-16 2:03
professionalJohn C Rayan18-Jul-16 2:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.