A
A
Alew2015-03-27 18:25:21
JavaScript
Alew, 2015-03-27 18:25:21

How is behavior modularity achieved in ASP.NET MVC?

I have rich experience in developing desktop applications in C# and highly appreciate the charms of the OOP approach.
A production need requires adding a fairly complex (for me) form to an existing asp.net mvc application using a combination of html + js that is still obscure.
The difficulty is to display a list of previously unknown elements, which in the backend are classes inheriting a common base abstract class. Elements can differ quite significantly and fence the garden for all occasions on the main page with checking the type of the list element and a piece of logic responsible for generating the display, I really didn’t want to, and as a result I did it based on ParitalView depending on the element type.
But if something acceptable happened with the display, then I could not understand how to encapsulate the behavior described in JS in each individual element.
Total:
In order to provide all elements with behavior, you have to put all the JS code on a common page.
Is there a way to put JS code in an individual PartialView ?
Perhaps I generally approach the issue from the wrong side, and ask you to poke your nose where it is described how such things are implemented.
The application is written in asp.net mvc 3, aspx, jQuery
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kamilgarey, 2015-04-02
@Alew

In order to provide all elements with behavior, you have to put all the JS code on a common page.

And this is correct from the point of view of FrontEnd. Otherwise, you will have to piece together the JS code scattered here and there.
If you want OOP - this is implemented by the programming language and not by the layout language.
So you need JS to be responsible for its rendering, not HTML which needs JS.
You might want to look into JS libraries (and frameworks): Angular, Ember, Knockout, Backbone, etc.
But this is a good solution. For him, you need to know JS well enough.
Plus, using any of the listed libraries seems too heavy for just one form.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question