I'm working on a WinFormApp that is using a WebView as my UI (the razor part). I have 2 files that exist in the same directory (Index.razor and Test.razor).
Using HTML, I have setup so list items (Index and Test) that should open the appropriate page when I click on the appropriate item. However, I cannot seem to get this to work. I have tried basic with no success. I have added the #page tags but this doesn't help. I have also tried using but this only seems to remove my clickable link.
I feel like I'm missing something obvious, and I'm not sure what. Any guidance would be greatly appreciated.
Here is my Home code(Index.razor). Right now Test.razor just contains a header to show it switched pages:
<div class="header">
<h1>Index Page</h1>
</div>
<div class="main">
<div class="ui-options">
<ul>
<li>Index</li>
<li>Test</li>
</ul>
</div>
</div>
#code {
}
Related
Hi I am trying to show list items in bootstrap columns but this code show list in vertical straight line
<div class="row">
<% var registragionNumberList = AppCalculations.GetInstance().GetRegistrationNumber();%>
<%
foreach (var item in registragionNumberList)
{%>
<div class="col-md-4">
<textarea> item </textarea>
</div>
<%} %>
</div>
please review and correct.
The code that you have provided works fine for me - it shows the results in three different columns so the issue isn't with the code that you have provided. I would guess that the issue is with bootstrap not being loaded correctly, do you have a script tag for bootstrap on the page?
If bootstrap is loaded and you are still seeing the issue then it might be worth seeing if there is some other styling that is causing an issue, try putting your code on an empty page with just boostrap and the code that you have put above.
I am trying to implement what I think is a pretty standard "dashboard" layout. The trick is I know ASP.NET but not so familiar with MVC so this is a learning project.
I have read many an article and they have helped me progress right to the point where I am very stuck and confused.
Part of my confusion comes from an existing advanced MVC project that I am familiar with from a user perspective. This helps in that I am able to pick through the source code and match up what I am learning to what I have seen from the user perspective.
This is not the problem just an example...
For example I read here what I believe is a very good introduction to the concepts. (http://www.codeproject.com/Articles/383145/RenderBody-RenderPage-and-RenderSection-methods-in)
In the MVC project I get to pick through however I see in the _Layout
#if (IsSectionDefined("statusbar"))
{
#RenderSection("statusbar")
}
however #section statusbar is not defined in the _Layout. If I do a global search for #section I find this:
#{
Layout = "~/Views/Shared/_Layout.cshtml";
}
#section header
{
}
#section headermenu
{
}
#section statusbar
{
}
#RenderBody()
So am I correct in guessing that statusbar is defined but it is an empty shell?
If it is an empty shell how does it get populated...cause when the project is running the statusbar does indeed have information???
So again this isn't my problem it is just an example of how the information at hand is confusing me.
This IS the problem:I'm not sure when to use PartialView, RenderSection...etc
My layout renders goofy. What is goofy? The only thing I can think of is to show you a screenshot of what happens.
What I want...
Here is the code used to generate these pages. The tags etc. for bootstrap etc. are omitted for brevity.
_Layout.cshtml
<!DOCTYPE html>
<html lang="en">
<head>
<title>#PageTitle</title>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
Header Stuff
</div>
</div>
<div class="row">
<div class="col-md-4">
#RenderBody()
</div>
<div class="col-md-8">
Main Content
</div>
</div>
<div class="row">
<div class="col-md-12">
Footer Stuff
</div>
</div>
</div>
</body>
</html>
Index.cshtml
#model DashboardModel
#{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="col-md-1">
<nav id="Navbar" class="navbar navbar-left" role="navigation">
<div id="organizer">
#(Html.Kendo().PanelBar()....etc....)
</div>
</nav>
</div>
<div class="col-md-3">
This is a place holder for my subnav...????
</div>
Stuff1Link cshtml
#model StuffModel
<div style="height:400px; border:dashed; border-width:thick;">
#{ Html.Kendo().MobileLayout().Name("mlay_PropStatus"); }
#(Html.Kendo().MobileView().....
</div>
Seems like layout is not put in Stuff1Link.cshtml
Can you put it like,
#{
Layout = "~/Views/Shared/_Layout.cshtml";
}
1.If your view just has some Html code just use "PartialView" :
#Html.Partial("_theLastPost")
2.If your view has controller for passing data it's better use "RenderAction":
#{ Html.RenderAction("_theLastPost"); }
and its controller
public PartialViewResult _theLastPost()
{
var a = (from c in db.Posts
orderby c.ID_Post descending
select c);
return PartialView(a);
}
3.I do not use render section . For more information about RenderSection go asp.net mvc layouts and sections with razor
I've got a post on my blog that discusses some of this you might want to check out.
The layout code you're referencing doesn't make much sense. The only purpose to declaring an empty section, really, is to fulfill a requirement that it exists, when you don't want to actually pass anything there. Since the layout is what defines whether it must be present or not, it makes no sense for it to exist there, empty. More than that, if you implement a section in your base layout, you'll get a runtime error because there's no place higher in the view chain where it's defined.
Long and short, to provide a place holder in your layout for a section you use:
#RenderSection("SectionName", [true|false])
The boolean param indicates whether views that utilize this layout must implement the section; false means it's optional, while true means it's required.
To implement a section in a view, you use:
#section SectionName
{
...
}
If you have a layout that inherits from another layout, that layout must implement all required sections in the layout it inherits from. If you want the the section to be available to views that utilize the sub-layout, you must redefine the section in the section implementation:
_Layout.cshtml
#RenderSection("Foo", true)
_SubLayout.cshtml
#{ Layout = "Views\Shared\_Layout.cshtml"; }
#section Foo
{
#RenderSection("Foo", true)
}
Finally, as to partial views vs. sections, it all comes down to whether you want to insert something into the layout or the view. For example, sections are most commonly used for inserting link tags to CSS files in the head or script tags before the closing body tag, where the view itself would not be able to touch directly. However, it's almost an apples and oranges comparison. Partials can be utilized in the layout, in the view, or even in a section. Whereas, sections can only be utilized in the layout.
What is the best method to render some navigation hyperlinks depending on which page the user is on (I am using C# MVC 4).
I have a _layout.cshtml which looks like the following (shortened down for display purpose).
<body>
#{Html.RenderAction("MainNav", "Navigation");}
<div id="container">
#RenderBody();
</div>
</body>
If a user navigates to /Home/Index then I would want the MainNav to render hyperlinks of Home | Management
Then if a user clicks Management that will change to Home | Company | Teams | Roles and will change again if they click one of these links.
Using Html.RenderAction() or Html.Action() would involve passing a parameter identifying your current view and using multiple if/else blocks to define what the partial should render. Instead you can use Razor sections to act as placeholders for specific content that can be placed anywhere in the layout.
In the layout, add #RenderSection(), in this case named "menu" to act as a placeholder for your menu links
<div id="sidebar">
#RenderSection("menu", required: false)
</div>
<div id="container">
#RenderBody();
</div>
Then in each view, add #section menu { ... } containing the links to display
Index.cshtml
// content to be displayed
#section menu {
#Html.ActionLink("Home", .....)
#Html.ActionLink("Management", .....)
}
Management.cshtml
// content to be displayed
#section menu {
#Html.ActionLink("Home", .....)
#Html.ActionLink("Company", .....)
#Html.ActionLink("Teams", .....)
#Html.ActionLink("Roles", .....)
}
The more you think about it, the more complex the problem you're describing becomes. So I tend to use a library. Even though it might seem overkill at this point, but in my experience it pays off later:
<body>
#Html.MvcSiteMap().Menu()
<div id="container">
#RenderBody();
</div>
</body>
This is all you need to do when using https://github.com/maartenba/MvcSiteMapProvider
Install-Package MvcSiteMapProvider
Just annotate your actions like this:
[MvcSiteMapNode(Title = "Menu Title")]
i am using mvc 4 application. actually my application it should running correctly by suddenly it showing compilation error and cleared all the temp files also it not working please help me
My error is:
View Code
<div id="page-wrapper">
<div class="row">
<div class="#ViewBag.HideClass">
#ViewBag.Message
</div>
<div class="col-lg-12">
<h2 class="page-header"> User Registration </h2>
<input type="hidden" id="MenuId" value="#(int)MenuDetails.MenuCompanyMaster" />
</div>
<!-- /.col-lg-12 -->
</div>
thank in advane
In your view page try changing this:
value="#(int)MenuDetails.MenuCompanyMaster"
To this:
value="#((int)MenuDetails.MenuCompanyMaster)"
In Razor syntax, an # section followed by a ( will end the C# code at the nearest matching ). In this case, it's just the #(int). The MenuDetails.MenuCompanyMaster section ends up being random other markup. By wrapping everything in an extra () it indicates to the Razor parser that it's all one expression.
However, I'm not certain if that will fully solve the problem that you have.
I have a partial view located in ~/Views/Partials/menubar.cshtml .
In my ~/Views folder i have a master page Called Menubar.cshtml <- this masterpage calls the
#{ Html.RenderPartial("menubar") } but it says:
"Cannot resolve partial view "menubar"
How can i fix this? I've tried the direct path like
#{ Html.RenderPartial("~/Views/Partials/menubar.cshtml") } still the same issue.
It has to be said that im using Umbraco 4.11 and Visual studio 2012 with resharper.
Here is the code for my masterpage (it has another masterpage):
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#{
Layout = "Master.cshtml";
}
<div id="header">
<img src="/images/logo.gif" width="259" height="65" />
<div id="sitedescription">
<h1>Runway</h1>
<h1>Off to a great start</h1>
</div>
#{ Html.RenderPartial("Menubar"); }
</div>
#RenderBody()
This is the code for my view, simplified just to get it working at first, there will be added some logic, otherwise the view would not make sense to have:
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
<div id="mainmenu">
<ul id="topNavigation">
<li class="home current">Home</li>
<li><a class="navigation" href="/"><span>Newz</span></a></li>
<li><a class="navigation" href="/"><span>Programmering</span></a></li>
<li><a class="navigation" href="/"><span>Support</span></a></li>
<li><a class="navigation" href="/"><span>Repair</span></a></li>
</ul>
</div>
<div class="mainmenucorner"> </div>
Here is an image of the structure in visual studio:
Can anyone tell me what i'm missing here, have spend hours on this now.
EDIT
I've found out that id i locate it under /Views/Shared it'll find it automatically.. It just seems that umbraco posts this page as the main page then - any thougts?
Try renaming the partial to _menuBar.cshtml, and render it using this:
#Html.Partial("_menuBar")
It works for me.