Base solution for your next web application
Open Closed

Angular 1.x Razor View with a Model object? #2981


User avatar
0
bilalhaidar created

Hi, Based on a user selection, I need to load a Razor View in Angular 1.x passing to it an Id. The Razor View shall have a model of a collection of some records that I need to loop over in Razor to render the records.

How to go about it? Can I load an angular view with a razor model?

I found it is easier to loop over collection in Razor to added some controls dynamically than to do so in Angular

Thanks Bilal


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Editing language texts works like you asked. You just need to add your collection as a parameter and get it in the target controller. This can help you <a class="postlink" href="http://stackoverflow.com/a/25298571">http://stackoverflow.com/a/25298571</a>.

    Thanks.

  • User Avatar
    0
    bilalhaidar created

    Maybe I didn't explain myself correct.

    I want to use a Razor For Loop to loop over data just as we do it when using MVC Model/Views. This is similar to the case when you call an MVC Controller Action that returns a View with a Model.

    The reason why I need this is because I need to get render form controls dynamically. So I would get a model of all fields to render, then one by one I embed an angular directive corresponding to that field.

    I would rather do that in Razor server-side rather than Angular as I read everywhere I shouldn't be doing DOM manipulation through the angular controller.

    Let me know if it is clear now, if not I will do more effort to explain.

    Thanks Bilal

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I think of two options.

    1 - You can use MVC redirect instead of using angular. 2 - We load cshtml files using jquery's load method which you can see here <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero/blob/master/src/MyCompanyName.AbpZeroTemplate.Web/Common/Scripts/ModalManager.js#L110">https://github.com/aspnetzero/aspnet-ze ... er.js#L110</a>.

    You can apply same method to load your cshtml file and then you can place your current view with the loaded cshtml file's content.

    I think second option is more convinient according to your explanation.

    Thanks.