In my simple ASP.NET application with MVC I'm trying use ViewBag.
In my view:
#{
ViewBag.Title = "SomeSampleText";
}
works.
But if I want to set ViewBag.Message = "SomeText" in controller it's null and after this in view it's also null.
Anyway InteliSence like #ViewBag or #model also not works.
It was null in View. I thougth the cause is missing some references, but it was spelling mistake in controller.
It's works but still I've issue with "red" #ViewBag and #model and missing InteliSence. It's not working also with all asp TagHelpers (I've proper dependencies and they work).
I want to add I created project from empty Asp.NET core template, not from Web Application or MVC templates.
Related
I'm building website using asp.net core 3.1 following tutorials, I'm working on bootstrap template, now I encountered strange problem that when I pass a strongly typed model to the view the layout of bootstrap not working, but if request the view without sending model it work...
Searching in google doesn't give a result.
Please enter the script and css with the view rendersection you are using and add the bootsrap links there
#Rendersection("Scripts",false) and #Rendersection("Style" ,false) include in layout after go to view add up #section Style ( bootsrap css link ) and down view add section script
I figured out what was the problem, It's was in svg-icons calls, it was starts with "~/svg-icons/" so I replaced it with "../svg-icons/", so the problem solved.
Unable to access Url.ActionContext.View.Path
I have to show on particual Path/View/Action Call
How can i get path in ASP.Net Core MVC
in quick watcher Url.ActionContext.View.Path it shows value but can't use gives error
found solution for asp.net core MVC
//for View
string viewname= ((object[])((Microsoft.AspNetCore.Mvc.Routing.UrlHelper)Url).ActionContext.RouteData.Values.Values)[1].ToString();
//for controller
string controllername = ((object[])((Microsoft.AspNetCore.Mvc.Routing.UrlHelper)Url).ActionContext.RouteData.Values.Values)[0].ToString();
We are currently upgrading an existing site from MVC 3 to MVC 4 and so far we have encountered these two issues with the razor views : enter link description here and
enter link description here
our main interest in MVC 4 is web api so razor takes a back seat, is there a way to configure MVC 4 to use Razor 1, my question is not to tackle a specific error configuring this but: is it possible at all?
I believe that you should be able to register the original Razor View Engine in the Global.asax.cs at startup... And remove the Razor 2 View Engine...
I'm trying to inject a partial MVC 4 view into a durandal view. The MVC view contains a Kendo grid which I would like to include a bit like using compose in durandal.
Looking at How can I use cshtml files with Durandal? did not enlighten me enough I'm afraid.
Does anyone have any further insight they would like to share? How would I include the MVC view in my durandal view?
I.e. my durandal /App/views/home.html should somehow include the result from my MVC view /Views/Data/index.cshtml
Thanks, watching the SPA course and reading this thread: https://groups.google.com/forum/#!topic/durandaljs/hpfZB-WFEXk helped solved my issue.
I ended up using Youngs approach, it was only when I saw the example I finally understood...
I recently installed ASP.NET MVC 3 via web platform installer. I don't have the intellisense support for ViewBag in Razor view. Intellisense works fine with model in Razor view. I tried to rebuild solution, disable ReSharper... but I couldn't get it to work.
Any help would be greatly appreciated.
The ViewBag property is typed as dynamic, which means that there is no IntelliSense.
ViewBag is an alias/alternative syntax for accessing the ViewData dictionary. The two following lines of code are equivalent:
ViewBag.Message = "My message";
ViewData["Message"] = "My message";
ViewBag offers a slightly terser syntax than ViewData. Also notice that accessing ViewData using string keys also provides no IntelliSense, so you don't really lose any functionality.
One last note is that ViewBag and ViewData use the same backing storage, so that setting a property using one method makes it available using the other method:
ViewBag.Message = "My message";
string message = ViewData["Message"];
// message is now "My message"
Adding to marcind's answer of the ViewBag being dynamic:
If you want intellisense, then you're going to have to pass in a strongly typed object and then in your view, you can set:#model Namespace.YourModel which will give you intellisense when you try to do #Model.Property