Separated elements overlooked, now combined - c#

Currently in the process of learning MVC and I think it's interfering with HTML code. I have just a basic navigational menu as a list and two <li> items seem to combine into one. Any way to make sure the two are separated when live?
#if ((Request.Url.AbsolutePath.ToString().ToLower() != "/home/index") && (Request.Url.AbsolutePath.ToString() != "/"))
{
<nav data-spy="affix" data-offset-top="500" style="border-radius:0px; left: 0" ng-hide="sideBar" id="nav">
<img src="~/Content/images/open.png" ng-model="sideBar" id="sideBarOpen" style="left:0px; top:0;"/>
<div id="sideBar" style="left: -200px">
<ul>
<li> Home </li>
<li><br /></li>
<li>About Me</li>
#############
<li>Experience</li>
<li>Resume</li>
############ These two seem to be recognized as 1 <li> and not two.
<li>Contact</li>
</ul>
<img src="/Content/images/myPic.jpg" />
</div>
</nav>
<div id="sideBarBack" style="width:0%;">
</div>
}

Youre missing a quotation mark in the id="> part. This is not a valid html so your wen browser tries to workaround that resulting in the two elements combined.
To fix that instead of:
<li>Experience</li>
use a correct tag attribute id="":
<li>Experience</li>

Related

How to add a line break in ASP.NET Boilerplate menu from Navigation Provider with localization

I have defined menu items using the Navigation Provider with localization. How can I add a line break in the middle of the menu name?
Navigation Provider
public override void SetNavigation(INavigationProviderContext context)
{
context.Manager.MainMenu
.AddItem(
new MenuItemDefinition(
"Menu Item",
new LocalizableString("MenuItem", MyAppConsts.LocalizationSourceName),
url: "#/menuitem",
icon: "fa fa-clipboard"
)
);
}
My Localization Source File
<?xml version="1.0" encoding="utf-8" ?>
<localizationDictionary culture="en">
<texts>
<text name="MenuItem" value="Menu Item" />
</texts>
</localizationDictionary>
cshtml file where the menu is created
<div class="sidebar-inner">
<nav>
<ul class="nav nav-sidebar">
<li ng-repeat="menuItem in vm.menu.items" ng-class="{active: vm.currentMenuName == menuItem.name}" class="nav-parent">
<a ng-if="!menuItem.items.length" ng-href="{{menuItem.url}}"><i class="{{menuItem.icon}}" ng-if="menuItem.icon"></i><span>{{menuItem.displayName}}</span><span class="fa arrow"></span></a>
<a ng-if="menuItem.items.length" href="" ><i class="{{menuItem.icon}}" ng-if="menuItem.icon"></i><span>{{menuItem.displayName}}</span><span class="fa arrow"></span></a>
<ul ng-if="menuItem.items.length" class="children collapse">
<li ng-repeat="menuSubItem in menuItem.items">
<a ng-href="{{menuSubItem.url}}"><span>{{menuSubItem.displayName}}</span></a>
</li>
</ul>
</li>
</ul>
</nav>
</div>
I want it shown like
Menu
Item
Not like this
Menu Item
Thank you in advance.
Try add an split filter to angular, and change your code to:
<span>{{menuSubItem.displayName | split:' ':0}}<br /> {{menuSubItem.displayName | split:' ':1}}</span>
See How to split a string with angularJS to how to add split filter.
As you can see in the file i said in comments, there is an ul-li tags to creating menu, which means you can change the view decoration with css.If you using bootstrap simply change <div class="menu"> to <nav class="navbar navbar-default"> and change <ul class="list"> to <ul class="nav navbar-nav">.
I have figured it out using string split. In the XML source I have added a '$' where I want to break the menu name into two lines.
<texts>
<text name="MenuItem1" value="Long$Name" />
<text name="MenuItem2" value="Short Name" />
</texts>
Then I used string split to break the menu display name into two and displayed it in two lines with tag.
<a ng-if="!menuItem.items.length" ng-href="{{menuItem.url}}">
<i class="{{menuItem.icon}}" ng-if="menuItem.icon"></i>
<span>
{{menuItem.displayName.split('$')[0]}} <br> {{menuItem.displayName.split('$')[1]}}
</span><span class="fa arrow"></span>
</a>

opening another form from an <a>

I have a project in Visual Studios 2017 with this block of code in it. I just went to remake it in on my work computer (running 2015). Is there a reason why the middle two links don't work anymore?
The code doesn't even turn purple in the IDE. The top screenshot is from my laptop, the bottom screenshot is from my work computer (where the trouble is) https://gyazo.com/2968018e89c24748d48cb2291dce50d3?token=e038af6931608caede27c103a0365184
<div class="col-sm-6">
<div class="well well-sm" style="background-color:lightcyan">
<h4>AVAS for Opperations</h4>
<div class="list-group">
AVAS Time-Space Chart <img src="https://cdn1.iconfinder.com/data/icons/education-set-4/512/information-512.png" class="w3-round" alt="Denmark" style="width:3%">
History by Bus/Run/Operator <img src="https://cdn1.iconfinder.com/data/icons/education-set-4/512/information-512.png" class="w3-round" alt="Denmark" style="width:3%">
<a asp-area="" asp-controller="Home" asp-action="Legal" class="list-group-item" data-toggle="tooltip" title="(Make a list of stops and timepoints for a bus for an hour)">Bus-Hour History <img src="https://cdn1.iconfinder.com/data/icons/education-set-4/512/information-512.png" class="w3-round" alt="Denmark" style="width:3%"></a>
<a asp-area="" asp-controller="Home" asp-action="Legal" class="list-group-item" data-toggle="tooltip" title="(Make a list of buses passing a selected stop)">Bus-Stop History <img src="https://cdn1.iconfinder.com/data/icons/education-set-4/512/information-512.png" class="w3-round" alt="Denmark" style="width:3%"></a>
</div>
</div>
</div>
Maybe you are missing Razor Language Services.
Check this question.

Xpath grabbing separate text in between link nodes

I'm currently retrieving text from inside <a> tags utilizing HtmlAgilityPack:
foreach (HtmlNode node in html.DocumentNode.SelectNodes("//div[#class='acTrigger']/a"))
{
lblTest1.Text = lblTest1.Text + ", " + node.InnerText.ToString();
}
and the web code looks like this
<li>
<div class="acTrigger">
<a href="/16014988/d/" onclick="return queueRefinementAnalytics('Category','Battery')">
Battery <em> (1)</em>
</a>
</div>
</li>
<li>
<div class="acTrigger">
<a href="/15568540/d/" onclick="return queueRefinementAnalytics('Category','Brakes')">
Brakes <em> (2)</em>
</a>
</div>
</li>
<li>
<div class="acTrigger">
<a href="/11436914/d/1979-honda-ct90-cables-lines" onclick="return queueRefinementAnalytics('Category','Cables/Lines')">
Cables/Lines <em> (1)</em>
</a>
</div>
</li>
Currently it is returning to me: Battery (1), Brakes (2), Cables/Lines (1) which is obviously all of the inner text. What I would like to know is how to split the two bits apart so I can store them each in a list for later usage. Something along the lines of: Battery, 1, Brakes, 2, Cables/Lines, 1 so as they are returned to me I can just toss them into lists.
The text in between the <em> tags are the number of results on the page that the <a> is taking you to. I could just parse the entire string after getting the line of text, but I feel as if there is a method to do this automatically with XPath and return one piece at a time for me to handle and store. I am very new to XPath and have been attempting to solve this for multiple days myself with no avail. Any help would be greatly appreciated.
Change your XPath expression to //div[#class='acTrigger']/a//text()[normalize-space()] separate text nodes.

Parse error on c# on ul li tags

I'm trying to make a dropdown for login in with this code:
<ul>
<li class="mega-menu mega-menu-custom reserved2">
Access
#if (Request.IsAuthenticated) {
<ul>
<li>
<a>Login</a>
<ul>
#using (Html.BeginForm("Login", "Main", FormMethod.Post))
{
<li><a class="custom-a-menu">Email</a></li>
<li>#Html.TextBoxFor(a => a.Email, null, new { #class = "custom-input" })</li>
<li><a class="custom-a-menu">Password</a></li>
<li>#Html.PasswordFor(a => a.Password, new { #class = "custom-input" })</li>
<li>¿Forgot password?</li>
<li><button type="submit" class="button primary custom-btn">Iniciar</button></li>
}
</ul>
</li>
<li>
<a>Registrarse</a>
<ul>
<li><a class="custom-a-menu">¿Interested in our services?</a></li></br>
<li>¡Register Now!</li>
</ul>
</li>
</ul>
}
</li>
</ul>
But when it always gives me a parse error on the ul end thag behind the }
I'm trying to hide the register and the login form when the user is authenticated, but I haven't yet added the else part, I'm stuck at this point.
the error is:
Parser Error Message: Encountered end tag "ul" with no matching start tag. Are your start/end tags properly balanced?
Am I missing something here?
What you have there will generate markup that looks like this:
<ul>
<form>
<li>email:</li>
...
</form>
</ul>
The form is the first child of ul and the children of ul should be li's.
Put the ul inside of #using (Html.BeginForm("Login", "Main", FormMethod.Post)), i.e.:
#using (Html.BeginForm("Login", "Main", FormMethod.Post)){
<ul>
<li>...
Also, as others have pointed out you have a </br> in your code. It should be <br/>
The cause of this error is the </br> at the end of this line:
<li><a class="custom-a-menu">¿Interested in our services?</a></li></br>\
If you remove that, the error will go away. You'll still have invalid HTML until you fix the #using location, like Rui's answer shows, but the error will no longer happen.
.Net (and especially MVC in .Net) does not like invalid HTML. Invalid HTML will cause all sorts of problems with the view rendering engine, such as this.
The direct issue here is the line break just after "Interested in our services", change
</br>
to
<br/>
and your code will compile, but there are other issues as others have pointed out.
When I post this code into VS, I get an error on </br>... it doesn't like that syntax (and it's not valid HTML anyway). Use <br/> instead.
In addition, I am not sure why that </br> is there in the first place... <li> elements are block level. Use CSS styling to create gaps, not <br>.

Max Value with Substring with HTML Agility Pack

I can't seem to get this xpath query to work with the HTMLAgilityPack with this code and I was wondering if anyone had any suggestions.
This is the query I have so far, but I can't seem to get it to return a number.
DocumentNode.GetAttributeValue("max(a[(#class='shackmsg')]/#href/substring-after(.,?id='))", "");
I'm trying to get the MAX value in the href attribute after the = sign on all hrefs with a class of shackmsg.
How long is the beta live before it goes retail? No one knows. We do know t</span> : </a><span class="oneline_user ">legsbrogan</span>
</div>
</li>
<li id="item_31218936" class="">
<div class="oneline oneline3 op olmod_ontopic olauthor_189801">
<a class="shackmsg" rel="nofollow" href="?id=31218936" onclick="return clickItem( 31218933, 31218936);"><span class="oneline_body"><b><u><span class="jt_yellow">Current Multiplayer Servers</span>!</u></b>
<span class="jt_sample"><span class="jt_green">Nighteyes's Japan Server: </span> <span class="jt_lime">(PvE)</span>: <b>211.15.2.34</b></span>
<span class="jt_sample"><span class="jt_green">zolointo's Canada Server: </span> <span class="jt_lime">(</span></span></span> : </a><span class="oneline_user ">legsbrogan</span>
</div>
</li>
<li id="item_31218938" class="last">
<div class="oneline oneline2 op olmod_ontopic olauthor_189801">
<div class="treecollapse">
<a class="open" rel="nofollow" href="#" onclick="toggle_collapse(31218938); return false;" title="Toggle">toggle</a>
</div>
<a class="shackmsg" rel="nofollow" href="?id=31218938" onclick="return clickItem( 31218933, 31218938);"><span class="oneline_body">Had fun freezing my ass off last night with a bunch of shackers. Not sure who started the big tower we f...</span> : </a><span class="oneline_user ">legsbrogan</span>
</div>
<ul>
<li id="item_31218966" class="">
<div class="oneline oneline1 olmod_ontopic olauthor_128401">
<a class="shackmsg" rel="nofollow" href="?id=31218966" onclick="return clickItem( 31218933, 31218966);"><span class="oneline_body">wasn't me. I hung out on my ship for a bit listening to your kid play Christmas songs for a bit and then ...</span> : </a><span class="oneline_user ">jonin</span><a class="lightningbolt" rel=\"nofollow\" href="http://www.shacknews.com/user/jonin/posts?result_sort=postdate_asc"><img src="http://cf.shacknews.com/images/bolt.gif" alt="This person is cool!" /></a>
</div>
</li>
<li id="item_31219008" class="last">
<div class="oneline oneline0 olmod_ontopic olauthor_8618">
<a class="shackmsg" rel="nofollow" href="?id=31219008" onclick="return clickItem( 31218933, 31219008);"><span class="oneline_body">haha i heard you guys booby trapped some poor sap's space ship</span> : </a><span class="oneline_user ">Break</span><a class="lightningbolt" rel=\"nofollow\" href="http://www.shacknews.com/user/Break/posts?result_sort=postdate_asc"><img src="http://cf.shacknews.com/images/bolt.gif" alt="This person is cool!" /></a>
</div>
</li>
</ul>
Any suggestions?
There are two problems as far as I can see:
You're only scanning for anchor tags in the current context. You probably want to extend to scan everywhere (use // in the beginning of your query):
//a[#class='shackmsg']/#href/substring-after(., '?id=')
Note that I removed a pair of unnecessary parenthesis.
If I'm not completely mistaken, HTML Agility Pack only supports XPath 1.0 (yet I'm not totally sure). While System.Xml.XPath says it implements the XPath 2.0 data model, it does not actually implement XPath 2.0 (probably this is done so third party APIs can implement this API and offer XPath 2.0/XQuery support at the same time). Also have a look at this discussion on .NET's XPath 2.0 support.
Missing XPath 2.0 support would show up as two problems:
Function substring-after(...) does not exist.
A solution for your problem could be to use string-lenght($string) and substring($string, $start, $length) to extract the last n digits, or translate(...) to remove some characters:
translate('?id=31219008', '?id=', '')
will remove all occurences in the character class [?id=] (yet it is none, I just want to highlight it does not match strings, but individual characters of this set!).
You cannot apply functions in axis steps. This means, you cannot find the maximum value of substrings.
Possible solution: Only fetch all substrings and find the maximum from outside XPath.
You can combine XPath with HTML Agility Pack and make the following code :
var value = doc.DocumentNode.SelectNodes("//a[#class='shackmsg']").Select(
x => x.Attributes["href"].Value.Substring(4)).Max();
Console.WriteLine(value);
And this output :
31219008
In this code I assume to always exist the href attribute and always have the following structure :
"?id=XXXX"

Categories