|
you branching out into lighting?
http://www.phi-lighting.com/product/vew/[^]
which flavour of MVC are you on as the way bundles work changes between 4 and 5
You cant outrun the world, but there is no harm in getting a head start
Real stupidity beats artificial intelligence every time.
|
|
|
|
|
I'm using MVC5.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
be thankful then as MVC 4 version was a nightmare
You cant outrun the world, but there is no harm in getting a head start
Real stupidity beats artificial intelligence every time.
|
|
|
|
|
Well then - not much has changed, evidently.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I've avoided MVC these past years because I thought it was just another 'pattern du jour' but I guess it's not going away so I've been learning it slowly when I can.
The best, easiest example I've found of using MVC so far has been the CodeIgniter[^] framework. Even if you never intend to use PHP with CodeIgniter, it makes the whole concept so easy and simple that you wonder what took you so long to use MVC
|
|
|
|
|
DaveX86 wrote: I've avoided MVC these past years because I thought it was just another 'pattern du jour' but I guess it's not going away so I've been learning it slowly when I can.
As a concept, it makes sense. Forcing an implementation down my throat doesn't make sense because quite frankly, sometimes MVC is simply best as just an organizational concept rather than a law by which every view MUST have a controller, every transfer of data from the database to the client MUST go through a model (especially when transforming a DataTable to JSON is a one-liner with NewtonSoft) and vice-versa, etc...
MVC, like MVVM is a great guideline, but the religiosity of it I can leave behind.
Marc
|
|
|
|
|
Well said. In the beginning MVC seemed like just another thing Microsoft was trying to flog so you'd have to upgrade Visual Studio yet again...that made me leery of it too.
|
|
|
|
|
DaveX86 wrote: just another thing Microsoft was trying to flog
The whole concept comes originally (more or less) from Java, then was picked up by Ruby on Rails which used it quite effectively, but even there it's passe what with more responsive, AJAX'd web designs. So, ironically, Microsoft is (as usual) late to the copycat game, haha.
Marc
|
|
|
|
|
Actually, AFAIK, the whole MVC concept is way older than Java. If I recall correctly, it's a SmallTalk "thing" and also was somewhat "popular" for C++ GUIs, too.
#SupportHeForShe If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams
You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
Only 2 things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein
|
|
|
|
|
TheGreatAndPowerfulOz wrote: f I recall correctly, it's a SmallTalk "thing"
Ah! You're right! I'd forgotten about that.
Marc
|
|
|
|
|
Marc Clifton wrote: MVC, like MVVM is a great guideline, but the religiosity of it I can leave behind.
I completely agree with you. I love MVVM, but I'm not over the top. There are some real fanatics out there who jump up on the table and scream if you so much as open a WPF code-behind.
The only concern I always keep in mind is... when you start regressing away from the pattern, at some point it ceases to be MVC/MVVM/[insert pattern name here].. Then what do you have left? Some kind of hybrid? Or is it just code all over the place? Hard to say.
If it's not broken, fix it until it is
|
|
|
|
|
Coder For Hire wrote: Or is it just code all over the place?
Ideally, you'd have some loosely coupled, not tied to a framework, potentially re-usable, probably more easily unit-testable, code.
Marc
|
|
|
|
|
Just a personal preference but I tend to steer clear of jquery UI stuff and use Bootstrap instead - I think things work nicer, especially for mobile devices, and (and in my opinion) it's a lot easier to customise/extend than jquery UI.
I like ASP.NET MVC, but the thing I didn't like was having to create a controller for every view (seemed a bit too much like the old webforms code behind files), so I created a NuGet package which intercepts the routing to use a built in "standard" controller if no controller or action is defined for a route.
It means you can just add views without a controller. If you find you need a controller for a specific view/action then you can add it and it gets picked up automatically
NuGet: https://www.nuget.org/packages/ControllerLess/[^]
Source: https://github.com/brentj73/ControllerLess[^]
How do you know so much about swallows? Well, you have to know these things when you're a king, you know.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
Brent Jenkins wrote: I like ASP.NET MVC, but the thing I didn't like was having to create a controller for every view (seemed a bit too much like the old webforms code behind files),
[shameless plug] Exactly the point I made in my just finished e-book on web servers, coming out soon! [/]
Marc
|
|
|
|
|
It's odd that I don't really hear that many devs complain about it. Especially when a lot of view controllers in AJAXified apps often have no logical code in them apart from:
protected void ActionResult Index()
{
return View();
}
I've seen projects with dozens (even hundreds) of view controllers with nothing but that in them.. If it was any other class, everyone would be ranting about re-usability, but call it a "view controller" and everyone just accepts that that's the way it is
How do you know so much about swallows? Well, you have to know these things when you're a king, you know.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
Brent Jenkins wrote: I've seen projects with dozens (even hundreds) of view controllers with nothing but that in them..
Gads, isn't the controller class re-usable?
I tried my hand at Razor and hated the MVC approach, so I ditched it, and yes, especially useless on the server-side for AJAX'd / SPA implementations.
Marc
|
|
|
|
|
Marc Clifton wrote: Gads, isn't the controller class re-usable?
It is - with a big compromise in that you'd need to have a common set of action names across the application. But then obviously you're going to start returning different models for each view too..
You could make each inherited class or the base class generic too, but then you're still having to maintain 100 different controllers with code that's 99% the same..
Razor's handy at times, but I wouldn't use it for model binding or generating HTML personally, more just for helpers here and there.
AJAXified apps and SPA's certainly seem to make better use of the framework.
How do you know so much about swallows? Well, you have to know these things when you're a king, you know.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
A common set of action names?
how many views have you in the system if you have 100's of controllers?
and how many index's?
You cant outrun the world, but there is no harm in getting a head start
Real stupidity beats artificial intelligence every time.
|
|
|
|
|
A common set of action names, like: View, Edit, Save, Delete - if you like that kind of thing (I personally don't). But then some views might need other actions: ConfirmDelete, SaveAddress, AddItemToBasket, etc..
Basically, what we end up with is a view controller for every view (isn't that just the same as webform's code behind?)..
In enterprise web applications, there can be hundreds or even thousands of views (including partial views). Every one (in general) will have repeated code like using "standard" ASP.NET MVC:
protected void ActionResult Index()
{
return View();
}
Any action that does nothing except return a view is extraneous code in my book. You would't write code this way (multiple unique classes with repeated, near identical method bodies) in any other context, so why do we accept it with view controllers?
How do you know so much about swallows? Well, you have to know these things when you're a king, you know.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
why would you have different controllers for each action? unless each of the above action does exactly the same thing, in which case have one controller for all the similar actions
ie one controller to do all the saves, one to do all the deletes etc
but normally you have different information to save etc on each view, so group all the actions for that view in one controller, even if you have a single class that actually does the save it can be called from multiple controllers
you can even have multiple views using the same controller, so all your customer views go to one controller, all your sales views to another etc
as for your example you are not actually writing the same code what you are doing is using an inbuilt functionality to control flow, you don't seem to have a problem with using multiple @html.helpers functions, what you have I n
protected void ActionResult Index()
{
return View();
}
is a server side helper using its default functionality, that you are not using its full capacity does not make it invalid.
the system is called Model - View - Controller and is designed to pass data to the html by use of a model, have that data changed by the UI and then the Model is passed back to the controller for processing, that you are using it for what sounds like a different process does not make the concept invalid
You cant outrun the world, but there is no harm in getting a head start
Real stupidity beats artificial intelligence every time.
|
|
|
|
|
Bergholt Stuttley Johnson wrote: why would you have different controllers for each action? unless each of the above action does exactly the same thing, in which case have one controller for all the similar actions
You can group actions together for a view, but it is still one view controller for each view, isn't it?
Bergholt Stuttley Johnson wrote: that you are not using its full capacity does not make it invalid
I think that perhaps you're missing my point? Let me give a clearer example:
I have an application with a header, nav bar and a footer. I use a MVC layout file to bring the basic structure of my application to life. So far so good.. So I create a number of pages which look up data and present it to the user. The need for the controller code that I write is clear here - I'm performing some logic.
However, I have a set of pages - let's call them "help" pages, that do no database lookups and have no real logic. I still want to keep my header, nav bar and footer (with content appropriate to the logged in user, perhaps)..
In standard ASP.NET MVC I still have to add a view controller for each help page (view). I need to write a C# action. Whenever I add a new page (view) or rename pages (views) I need to update my C# code and recompile and publish the entire application.
How does that make sense? It's not a case of under-using the framework, it's day-to-day development. Some pages (views) need their own logic, others don't - the point is that with ASP.NET MVC, I have to write logic for every page (view) whether it's needed or not.
How do you know so much about swallows? Well, you have to know these things when you're a king, you know.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
I can see what you are getting at I think, firstly still not sure why you need a new controller for each view? if its only initialization then you can put them all in one controller, unless you are calling the views the same name!
whist I can see that three lines of code repeated numerous times may seem like a silly overhead, these three lines are initialising the MVC process, think of it as similar to initialising a variable, you do that hundreds of times too but accept that as part of the process.
as for updating well that is how things work, if you object to that then don't use MVC if you want the flexibility of MVC then you accept that its compiled and will need recompiling when you change code, if you don't want that then use a scripting language and HTML
You cant outrun the world, but there is no harm in getting a head start
Real stupidity beats artificial intelligence every time.
|
|
|
|
|
Bergholt Stuttley Johnson wrote: I can see what you are getting at I think, firstly still not sure why you need a new controller for each view? if its only initialization then you can put them all in one controller, unless you are calling the views the same name!
Not quite, as it's also relevant to actions within controllers. An example:
- Views
- Home
- Index.cshtml (pretty much static content)
- UsagePolicy.cshtml (pretty much static content)
- Customers
- Index.cshtml (pretty much static content)
- List.cshtml (a list of customers)
- Edit.cshtml (the "edit customer" form)
- Shared
With ASP.NET MVC as it currently stands, I need the following controllers and actions:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult UsagePolicy()
{
return View();
}
}
public class CustomerController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult List()
{
..Customer list logic
}
[HttpGet]
public ActionResult Edit()
{
..Form initialization logic
}
[HttpPost]
public ActionResult Edit()
{
..Form relevant logic
}
}
What I'm suggesting reduces the code down to this (HomeController is no longer needed):
public class CustomerController : Controller
{
public ActionResult List()
{
..Customer list logic
}
[HttpGet]
public ActionResult Edit()
{
..Form initialization logic
}
[HttpPost]
public ActionResult Edit()
{
..Form relevant logic
}
}
Surely reducing the amount of code down in any project makes sense more than writing the same code in different classes over and over again?
Bergholt Stuttley Johnson wrote: hink of it as similar to initialising a variable, you do that hundreds of times too but accept that as part of the process.
Not quite (again). I only add a variable where I have a use for it - it's optional. Actions (and controllers) are mandatory whether or not I have any logical code to add.
Common methods would normally be placed within a base class, or you might decide to add in a route, but that still means recompiling and re-publishing the entire application every time someone adds a new view/action name.
What I'm getting at is this: why not (in ASP.NET MVC) make actions (and controllers) optional, in that I only write them if I actually need to include some functional code? The default behaviour should be (in my opinion) that if a route is requested that goes through to a view without an action and/or controller, then it simply returns the view.
Bergholt Stuttley Johnson wrote: f you object to that then don't use MVC
I love ASp.NET MVC, but even the MVC guys themselves work on improving it. If we just accept things as they are, we'll never move forward
How do you know so much about swallows? Well, you have to know these things when you're a king, you know.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
so what you are saying is that it should create the controller/action code automatically if it isn't in your code.
ok but this allows the runtime exception if the view doesn't exist when the existing method will not compile if the view is missing
whilst it is a possible enhancement it does break the idea of the model-controller-view process, and whilst your example does show it may be a nice to have it is not the perceived flow and may have little traction in the future development of MVC, it will depend on exactly how much this is seen as an advantage over other enhancements
if you love it then you must except that their are something that are inherent to the way the architecture is and if you want this to change then perhaps MVC.net may not be the platform for you, MVC itself is not restricted to .net and there are flavours that are script code based and does not require compiling, however they don't have the razor engine
You cant outrun the world, but there is no harm in getting a head start
Real stupidity beats artificial intelligence every time.
|
|
|
|
|
Bergholt Stuttley Johnson wrote: so what you are saying is that it should create the controller/action code automatically if it isn't in your code.
No, that isn't what I'm saying. Perhaps it's easier if you take a look at the example project here..
Using ASP.NET MVC Without Controllers or Actions for Each View[^]
How do you know so much about swallows? Well, you have to know these things when you're a king, you know.
modified 31-Aug-21 21:01pm.
|
|
|
|
|