Parsing HTML with HTMLDocument class in C# - html-parsing

I want to get all the anchor () nodes of HTML from HTMLDocument object that have attribute href but should not have a title attribute

Related

Thymeleaf link with a string value

Can i place a string value in thymeleaf link instead of id and without first listing the database table contents. Like this
<a th:href="#{particularList/{type}(type=lcd)}">

Raw Querystring in ActionLink

In razor mvc helper, I can provide a querystring to ActionLink as a name value pair e.g. new {x = "something"}
How can I pass a querystring which is raw data and not name value e.g. if I have abc, I want it to show as <a href="mylink?something"> instead of <a href="mylink?x=something">
You can use Url.Action html helper method along with the anchor tag markup.
Test

Struts2 Jquery Ajax form serialize

I am learning Struts2 and have the following question on submitting a form with Jquery serialize. I have an action class where I have an object called Policy and the policy class has set of fields as shown below. With jquery ajax I want to set a json string in my Action class and would like to deserialize it to an object.
How much ever I try, I am not able to set the string I defined in my action class. Below is the code
Class CassPolicy{
String policyNumber;
String name;
//getsets for members
}
Action:
Class PolicyAction{
String cassPolicyString;
CassPolicy cassPolicy = new CassPolicy();
//getsets for members
String save(){
//In save method I want to convert the policyString to policy object
//policyString always returns null
}
}
JSP:
$.ajax({
url:PolicyAction.action,
type:'post',
data:$("#policyForm").serialize(),
async:true,
success:function(data){
}
});
<s:form id="policyForm">
<s:textfield name="cassPolicy.policyNumber" label="policyNumber"></s:textfield>
<s:textfield name="cassPolicy.name" label="name"></s:textfield>
</s:form>
I even tried in ajax something like data:{cassPolicyString:$("#policyForm).serialize()}
Can someone help me point to the right direction or what is the right way to achieve my task?
I figured it out finally.. The issue is form serialize does not give a json format. I used the code in below link to serialize my form as json object and added a interceptor ref element to my action in struts.xml which finally assigned my form values to cassPolicy object.
Convert form data to JavaScript object with jQuery

How do I render a single JSON value inside HTML?

When I return a JSon value, i simply want to put a string inside an existing div
EDIT: Let me Rephrase this: I want my MVC controller to return a JSON object to the UpdateTarget specified in the MVC AJAX call. Instead of returning "content".
Assume your JSON String looks like this:
var jobj = '{"name":"value"}';
and you have a div on the HTML with id mycontentdiv then
document.getElementById("mycontentdiv").innerHTML = jobj.name;
will take the "value" and place it in the div.
Without further details it is difficult to be more specific.

How can I add a class attribute to an HTML element generated by MVC's HTML Helpers?

ASP.NET MVC can generate HTML elements using HTML Helpers, for example #Html.ActionLink(), #Html.BeginForm() and so on.
I know I can specify form attributes by creating an anonymous object and pass that object for the (fourth in this case) htmlAttributes parameter where specifying an id for the element:
Html.BeginForm("Foo", "Bar", FormMethod.Post, new { id = "MyForm"})
But what about the class attribute? Obviously this does not work:
Html.BeginForm("Foo", "Bar", FormMethod.Post, new { class = "myclass"})
As that just throws random syntax errors when my view is requested, because it expects something else after encountering the C# keyword class.
I've also tried:
new { _class = "myclass"}
and
new { class_ = "myclass"}
But they also did not work, as the underscores get replaced by dashes.
I know that I can just as well write the HTML elements by hand or wrap the form inside a <div class="myClass">, but I'd still be interested to know how it is supposed to be done.
In order to create an anonymous type (or any type) with a property that has a reserved keyword as its name in C#, you can prepend the property name with an at sign, #:
Html.BeginForm("Foo", "Bar", FormMethod.Post, new { #class = "myclass"})
For VB.NET this syntax would be accomplished using the dot, ., which in that language is default syntax for all anonymous types:
Html.BeginForm("Foo", "Bar", FormMethod.Post, new with { .class = "myclass" })
Current best practice in CSS development is to create more general selectors with modifiers that can be applied as widely as possible throughout the web site. I would try to avoid defining separate styles for individual page elements.
If the purpose of the CSS class on the <form/> element is to control the style of elements within the form, you could add the class attribute the existing <fieldset/> element which encapsulates any form by default in web pages generated by ASP.NET MVC. A CSS class on the form is rarely necessary.

Resources