|
Brent Jenkins wrote: Even to add a single static HTML page I'd still need to create a new view controller
No you wouldn't. Just add the page (or, more ideally, the folder it's in) to an ignore route and let IIS serve the page natively.
|
|
|
|
|
And if I still want to use the shared layout or Razor?
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.
|
|
|
|
|
Then it's not an html page anymore.
|
|
|
|
|
So I have a MVC layout with a header, nav bar and footer and the content contains just this:
<p>Hello world</p>
In the world of standard ASP.NET MVC, I still have to create a view controller with an action to return my view.
That's what I'm talking about - the content of the view is static but I still need to code, recompile and publish.
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've never dynamically deployed cshtml, but I believe it's compiled on the fly.
Couldn't you create a catch-all route that passes the viewname as a parameter instead of the action name?
routes.MapRoute(
"my-route",
"{controller}/{viewname}",
new { action = "GetView" });
|
|
|
|
|
Surely better to just re-route views without an action (or controller) through to a default controller? For anything else, leave the "standard" behaviour.
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.
|
|
|
|
|
you could but why?
surely that the views are different, if they are purely html and not requiring a model you could just have a case statement and a redirect to view
I can see that having an action for every view is extra code but if you have so little in a controller maybe you should be thinking is MVC the right technology!
You cant outrun the world, but there is no harm in getting a head start
Real stupidity beats artificial intelligence every time.
|
|
|
|
|
you don't need to create a new controller if you don't wish, you could just use one controller for everything (yeuk) and use route mapping to wire it together
not sure I'd like to have to debug/fix it though
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: not sure I'd like to have to debug/fix it though
Is it any worse than fixing a hundred view controllers with the same code repeated a hundred times?
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.
|
|
|
|
|
yes as that would involve using a 3 foot wooden debugger to the responsible developer's kernel
You cant outrun the world, but there is no harm in getting a head start
Real stupidity beats artificial intelligence every time.
|
|
|
|
|
Doesn't every view controller have a default/initial action?
You could have a base class for view controllers I guess but then you're still tied into having a common default action name across the board.
That's where I came up with the idea of having a default controller that handles any routes that don't have the appropriate action and controller set up. When 99% of your calls go into WebAPI, view controllers are almost obsolete
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.
|
|
|
|
|
nope, you can use routes to define how this is organised, however I wouldn't recommend doing this
kinda misses the point of MVC
Routes are a very powerful bit of MVC and are underused
You cant outrun the world, but there is no harm in getting a head start
Real stupidity beats artificial intelligence every time.
|
|
|
|
|
Routes are powerful, but why do I need to recompile my entire application and publish the whole lot, just because I've changed the name of a view?
Even worse, if I add a static page I still need to add (under out-of-the-box ASP.NET MVC) a view controller, then re-compile and publish the entire application..
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 , if its a static page would you need it to be a view? html pages still work just fine
You cant outrun the world, but there is no harm in getting a head start
Real stupidity beats artificial intelligence every time.
|
|
|
|
|
And if I still want to use Razor there, e.g. @Html.Partial(...) ?
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 would have to see how its organised to work that out, it does seem to against best practices
I find I have very few actions that do nothing but return the view
You cant outrun the world, but there is no harm in getting a head start
Real stupidity beats artificial intelligence every time.
|
|
|
|
|
If you're creating AJAXified apps or SPA's then you'll probably have those kind of actions in every controller
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.
|
|
|
|
|
Not sure if I was using ajax in that way I would be using MVC at all, just use cshmtl pages in a asp.net app
sounds like you have found a way of using MVC that it was not design to do but in a way that works, no problem with that, however I do find it a bit harsh to condemn the technology just because you are using it differently to they way it was originally designed to work
You cant outrun the world, but there is no harm in getting a head start
Real stupidity beats artificial intelligence every time.
|
|
|
|
|
I'm not condemning it - it does at least provide a mechanism whereby you can "fix" this issue.
Bergholt Stuttley Johnson wrote: sounds like you have found a way of using MVC that it was not design to do but in a way that works
Just using plain old ASP.NET MVC with Microsoft WebAPI, TypeScript and KnockoutJS.. pretty much standard fare these days
..and I usually plug this in to make actions/controllers optional unless I actually need to write specific code for them..
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.
|
|
|
|
|
SPA's are to MVC as WPF is to Windows Forms.
Can you combine the two in a single application? Sure. If you want to have lots of headaches and duplicated code.
It's much simpler to do one or the other. In my SPA's I have exactly one web page: index.html, and zero page controllers. Everything is webapi and javascript. Then I'm not trying to do mental gymnastics around partial pages vs. partial views vs. shared views, or api controllers vs. page controllers (routing gets to be a mess when you go down this road).
|
|
|
|
|
Vark111 wrote: Sure. If you want to have lots of headaches and duplicated code.
Hey, that's my point Standard ASP.NET MVC means you end up with code in WebAPI and in the view controller for the same view.
I'd disagree about the headaches though - a single page app may only have one URL to a view, but depending how it's configured it could well be returning partial views as a HTML response to an AJAX call, as opposed to JSON encoded data (I've developed systems that do both). You can get just as many issues using ASP.NET MVC and Razor without AJAX or WebAPI once an application gets complex enough.
A SPA with only a few different HTML elements can be done without using partial views, but if you're working on a large-scale application it's just not practical to try and load every possible combination of HTML elements the first time you hit the page. One system I recently worked on (not my design) had over 6,000 views/partial views.
I really hate duplicated or unnecessary code, that's why I'm talking here about actually removing actions from view controllers that only return a view leaving only code that actually performs a logical function (or even better, removing the controller completely where only static content is contained in a 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.
|
|
|
|
|
I noticed earlier in the thread you mention using Knockout etc as your spa framework, and maybe that's where my disconnect is as I don't use knockout. I use angular, so all of my "partial views" are actually "partial html", which doesn't need a view controller.
|
|
|
|
|
If you're not running the views through ASP.NET MVC then you're right, there's no need for a view controller.
My point was more about having views where ASP.NET insists on me having to write a view controller with an action that simply returns the view. In those cases, the code I'm forced to write..
protected ActionResult Index()
{
return View();
}
..seems extraneous and is often found duplicated, even multiple times in individual view controllers at times.
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 don't know enough about jquery or bootstrap to form an opinion one way or the other. At the point I'm at, it would certainly be easy to abandon jquery-ui since the MVC5 template I'm using uses bootstrap (terrible name, btw) by default.
".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
|
|
|
|
|
You get a lot more bang for your buck with Bootstrap as you get all the responsive helpers and layout classes.
It's easy to customise too, so long as you get the LESS source (available on NuGet) rather than just including the Boootstrap CSS file (you'll end up unpicking loads of CSS in your own CSS file if you just use that).
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.
|
|
|
|