ASP.NET MVC Questions



  • I'm trying to learn ASP.NET MVC 5 in my own time to improve my career prospects (and move away from PHP), but there's so much information out there that I'm struggling to piece it all together in any meaningful way. I'm intending to rebuild the PHP web application that I created for my university project module so that I have a worthwhile application to work on. I'll probably throw the first version away, then build it again using the techniques that I've learned.

    I'll post questions here as they crop up, and will appreciate any help from people with experience in using these tools. I'm not expecting hugely detailed responses, but something to help me refine my searches. Even just the name of the facility that I should be using will be very helpful.

    That said, here comes my first question.


    I've been through a few basic tutorials, including this one which has been the most useful so far:

    Getting Started with Entity Framework 6 Code First using MVC 5

    It shows how to automatically create views using CRUD, but there's unnecessary code duplication. For instance, the Details view and the Delete view have sections that are identical:

    For some reason, these are implemented separately in the code, rather than being refactored into a single component and included on the two pages.

    What's the recommended way of pulling this content out into a separate place and then including it on the two pages?


    Also, book recommendations would be appreciated. I have this book and was previously working through it, but a bunch of the content was already outdated, and according to the reviews, the MVC 5 version hasn't been properly updated either, so I don't have much faith in it teaching current best practices.


  • FoxDev

    @Keith said:

    What's the recommended way of pulling this content out into a separate place and then including it on the two pages?

    Partial View



  • @RaceProUK said:

    Partial View

    Thanks, that helped me to find it in my book. Is there also a way of creating a section of a page with behavior that is defined in a single place? Something like an encapsulated widget?



  • is that not just a partial view still?

    you can provide parameters to a partial view as far as I can recall




  • FoxDev

    @algorythmics said:

    is that not just a partial view still?

    Yep, still a partial view 😄



  • @algorythmics said:

    is that not just a partial view still?

    @RaceProUK said:

    Yep, still a partial view

    Noice. Thanks for the help. :)



  • Scanning through that part of the book, I've also found child actions, which, in combination with partial views, seem to offer better encapsulation of behavior.

    I'll probably have to get the new version of that book and go through the whole thing. It's frustrating though, because by the time I've finished working through it and am ready to start my project, I'll have forgotten which of the techniques and features I need to use.

    EDIT: I've bought this for the Kindle. Hopefully it'll give me a decent overview.



  • im a fan of learn by doing, so if it were me (particularly since you are planning on throwing out v1 anyway) I would use the book to answer questions where possible rather than read the book, do the project.


  • Discourse touched me in a no-no place

    Learning by doing is good, though there's value in ensuring that you read through the whole book too. (If the book has exercises, try to do them.)



  • @algorythmics said:

    im a fan of learn by doing, so if it were me (particularly since you are planning on throwing out v1 anyway) I would use the book to answer questions where possible rather than read the book, do the project.

    For me, it's a tutorial (or first several chapters) to give me some basic competence, and then a throwaway project to polish it up.

    Re: MVC5 book. It's been years since I learned that, so I can't help you there. I think I went mostly by the apress book. Their books are super-boring, but generally competent and exhaustive.



  • @RaceProUK said:

    Partial View

    For this type of CRUD app you'd do better with display templates and editor templates than plain partial views.


Log in to reply