I have some HTML which is encoded as XML, for example:
html = "this is a test </a> test <em>test2</em> ... "
So when I try to load this into a WebView control, it doesn't correctly render the HTML:
myWebView.NavigateToString(html);
Just to be clear, I am not creating this HTML in this fashion, but am stuck with it. Is there a way to either render this to the control, or convert it to standard HTML first?
string html = HttpUtility.HtmlDecode("this is a test </a> test <em>test2</em> ... ");
Related
I have an HTML string that also contains a call to a partial view
When I render the string as such, it renders the HTML but not the Partial View.
My Partial file has the text Welcome to my Partial!
#Model.MyText = "This is my Text #Html.Partial('Partials/Partial') Done!";
#Html.Raw(Model.MyText)
Renders:
This is my Text #Html.Partial('Partials/Partial') Done!
Instead of:
This is my Text. Welcome to my Partial! Done!
How would I achieve this?
The razor snippet only works in the context of the .csharp file itself, not the rendered webpage. When you call #Html.Raw(Model.MyText), it correctly renders the string as html. However the resulting html is not parsed as C# code, it is just a string of text. This is not the way to achieve your desired result.
Everything you need done using C# must be done before the render. After rendering, its just html code/text.
I am getting html code in *.aspx.vb page. I want to display this content as HTML or web page, but instead it is getting displayed as html code using response.write()
str_ = Server.HtmlEncode(GetTemplateContents("email_customerActivation.htm", asz))
Response.ContentType = "text/html"
Response.Write(str_)
i think you are trying to hard ! you have a special control for this purpose:
asp-Literal = set it's innet html to what ever you need and you are good to go!
The HTML content I need to parse is the text in the marquee element as given below. I'm using C# with HTML Agility Pack to parse it, but a nullrefrence exception is thrown.
C# code is
var ht1 = ht.DocumentNode.SelectSingleNode("html/body/table/tbody/tr/td[2]/div[2]/marquee/text()").InnerText;
Part of HTML:
<html>
-<body ...
-<table id=..
-<tbody>
-<tr>
+<td.........
-<td
+<div ......
-<div style="width:100%;padding:0;margin:0;border
-style:solid;border-width:0;border-color:darkred;">
<marquee width="100%" height="20" bgcolor="" style="color:
darkorchid; font-size: 14" loop="3" behavior="scroll"
scrolldelay="90 scrollamount="5" align="middle" border="0">
your scrolling text - these are some samples - think of
possibilities</marquee>
<div>
Did you look in the direct source of the html file? If you only look in the html shown in a browser like Firebug/fox, it shows additional tbody tags, that are not actually in the file.
Therefore use:
var ht1 = ht.DocumentNode.SelectSingleNode("html/body/table/tr/td[2]/div[2]/marquee/text()").InnerText;
You usually do not want to use text() because, the text content of a node is already its text. And text() returns a set of text-nodes, not the concatenated text.
Therefore use:
var ht1 = ht.DocumentNode.SelectSingleNode("html/body/table/tr/td[2]/div[2]/marquee").InnerText
That page does not seem to be well formed HTML.
This worked for me though:
ht.DocumentNode.SelectSingleNode(#"html/head/table[1]/tbody/tr/td[1]/td/div[2]/marquee").InnerText;
I want to parse razor view file in c# . I have also used Html Agility Pack to parse razor view file but it failed to save correct file contents.
Basically i want to change some html elements inner html by server side using c#
<div id="content1">
<p>this contents i want to change </p>
<span>contes</span>
</div>
i want to change content1 inner html by c# like this
<div id="content1">
<span>#Function.gethtml()</span>
</div>
I have used html agility pack to change inner html contents but it is not parsing razor syntax function like
#Url.Content("abc.css") and other function
For more information
I have created a project in asp.net mvc3 for shoes and garments shops.Now i want to change css and html dynamically.i want to extract inner html from any html template file where element id will be "content1" and place this inner html in cshtml file where element id is "content1
Simply i want razor file parser that can parse both html and razor syntax like html parser
Is there any way to parse razor view file and it html elements.
Any Other solution
You want to access / modify razor content using server side content.
But MVC is a different way of building websites/applications to webforms.
There are now server side controls or webcontrols. You can use JQuery to do same.
I have a simple string variable that contains a portion of HTML inside. For example:
string contents = "<div><p>Hi how are you. Click here if you want to know more";
I want to include this HTML in page:
<div class="description">
#contents
</div>
However, it messes up the rest of the page because of unclosed tags.
Is there a function (or a helper) that reads and formats the HTML inside for example, to complete the HTML without errors:
#Html.DisplayProperHTML(contents)
This will render as:
<div><p>Hi how are you. Click here if you want to know more</p></div>
There is no such functionality built-in.
You can use the HTML Agility Pack to parse and fix broken HTML.