This code displays an number of li inside an ol - c#

This is what I should have posted in the first place.
This code displays an number of li inside an ol. Each li is represented on the page with a number(1 thru ...). Is there any way that I can access the current li number value with HTML, C#, Razor or JavaScript so that I can display it myself elsewhere on the page?
<div id="movieslist">
<ol>
#foreach(var row in data)
{
<li>
<table>
<tr>
<td width="950px" valign="baseline">#row.Name, #row.ReleaseYear, #row.Genre</td>
<td align="right" width="50px">
#{displayCount++;#displayCount;}
</td>
<td>
<select style="background-color:ThreeDFace">
<option>Choose Action</option>
<option onclick="window.location='dataMovies.cshtml?id=#row.id'">Google it</option>
<option onclick="window.location='EditMovie.cshtml?id=#row.id'">Edit Movie</option>
<option onclick="window.location='DeleteMovie.cshtml?id=#row.id'">Delete Movie</option>
</select>
</td>
</tr>
</table>
</li>
}
</ol>

I assume you mean the numbering that is automatically allied by the browser when ol or Ordered List is used.
With JQuery you could use .index()
In CSS3 you can use the nth-child pseudo-selector to style specific elements:-
http://reference.sitepoint.com/css/pseudoclass-nthchild

If you want to display it yourself, use ul and a counter. However, you can slightly modify the automatically displayed numbers as well.

This post will help you to achieve this.

Related

How do I select a button before text using Selenium C#

I have a bit of a dilemma. I have a table of 3 columns. Column 1 is a button to make that row active. The 2nd column is the name of the person. And the 3rd column is a button to view the person's details.
Using Selenium C#, I can search for a specific person in the table and click the button to View, using the code below:
currentDriver.FindElement(By.XPath("(.//*[normalize-space(text()) and normalize-space(.)='Name of person'])")).Click();
How do I select the button before the name of the person?
EDIT: Added HTML -
<table class="table table-hover>
<thead>...</thead>
<tbody id="listCompany">
<tr>
<td>
<span id="a5" class="badge btnActivateCompany clsActiveCompany15" ><i class="fas fa-times"></i></span>
</td>
<td>Test Director</td>
<td>
<button.>...</button>
</td>
</tr>
</tbody>
The class btnActivateCompany is used several times depending on how many rows exist. And the id changes depending on the rows as well. So I have to search to find the correct record and then select the span before it.
I tried the following to select the object:
currentDriver.FindElement(By.XPath("(.//*[normalize-space(text()) and normalize-space(.)='Test Director'])[1]/preceding::span[1]")).Click();
I get the feeling you've modified the HTML as you've posted. I guess you stripped out some data and typed other content in. You say you want the button before the person, but in your code the button is after the person?
Either way, both are achievable. I made a few quick additions to help visibility. If i'm wrong please correct me as it influences xpaths.
Quick change log: I ran your html through a beautifier, added text to all the columns for visibility, added "border=1" to the table, remove the . from button, added the </table> and duplicated the row so i can check unique objects are found.
This is the result: (useful if anyone else wants to chip in an identifier)
<html>
<body>
<table class="table table-hover" border=1>
<thead>...</thead>
<tbody id="listCompany">
<tr>
<td>
<span id="a5" class="badge btnActivateCompany clsActiveCompany15" >
<i class="fas fa-times"> Column 1</i>
</span>
</td>
<td>Test Director</td>
<td>
<button> Button in col 3
</button>
</td>
</tr>
<tr>
<td>
<span id="a5" class="badge btnActivateCompany clsActiveCompany15" >
<i class="fas fa-times"> Column 1</i>
</span>
</td>
<td>Second Row!</td>
<td>
<button> Button in col 3
</button>
</td>
</tr>
</tbody>
</table>
</body>
</html>
That renders like this:
Based on fact you say you can get the text in the middle column...
If you want the button in column 3, you can try xpath:
//td[text()='Test Director']/parent::*/td/button
If you want the span in column 1, you can try:
//td[text()='Test Director']/parent::*/td/span[contains(#class,'btnActivateCompany')]
In both of these instances this selects a unique hit in the source.
However, please note, this is dependent on the html provided. If there are other elements/attributes in the table the xpath might need more work. I'm happy to help more but you'll need to share more content.

MVC: Displaying table after button pressed

Hi I have a question is that possible to have function to display my table after the button was pressed, because now it's always on? I've tried with some IF functions but they weren't working.
My code:
#using (Html.BeginForm("Search", "Home", FormMethod.Post))
{
<br />
<span style="font-weight: bold">Tytuł filmu:</span> #Html.TextBox("VideoName")
<input type="submit" value="Szukaj" class="btn-primary" />
<br />
<br />
<table cellpadding="0" cellspacing="0">
<tr>
<th>
#Html.DisplayNameFor(model => model.ImageUrl)
</th>
<th>
#Html.DisplayNameFor(model => model.VideoName)
</th>
</tr>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.ImageUrl)
</td>
<td>
#Html.DisplayFor(modelItem => item.VideoName)
</td>
</tr>
}
</table>
}
If you put your markup inside a conditional block as follows:
#if (true)
{
#* PUT MARKUP HERE *#
}
Then the markup will only appear when the if condition is true.
Alternatively, you can use client-side code to simply hide the markup. I don't know which is best, because you haven't provided any details about what you are doing.
Instead of saying THE button, perhaps you should've talked about what kind of button you have and what is it supposed to do. If it works server side, use my first suggestion. If it needs to work client side, use my second suggestion.
You can do that in number of ways,
Javascript:
document.getElementById('mytable').style.display = 'block';
Give your table an ID and set its display to none; initially, then using javascript on the button click switch the table display to block;
function buttonClick(){
document.getElementById('myTable').style.display = 'block';
}
<table id='myTable' style='display:none;'>...</table>
<input type="submit" value="Szukaj" class="btn-primary" onclick='buttonClick()' />
Notes:
- It can be much easier if you are using jquery
- You can use event listener for the button click
Server side code:
On your action method set a TempData or ViewBag variable and then in the html check if this value exist, if true show the table
I am sure there are many other ways to do that but most of them will be around both ideas I listed.
You can have a button that toggles the visibility of the table, call the below function on the button onclick event to show or hide the table.
function toggleTable() {
var lTable = document.getElementById("YourTableId");
lTable.style.display = (lTable.style.display == "table") ? "none" : "table";
}
You have several good answers but it depends on exactly what you are trying to accomplish. I've used a variety of what has been provided. You mention showing table on button click. Do you also need to hide table if said button is clicked again? If so, client side jQuery and .toggle() could help.
$(document).ready(function(){
$("button").click(function(){
$("#myTable").toggle();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<button>Toggle</button>
<table id="myTable" style="border: 1px solid black; display: none">
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>

Combining ASP.NET Controller Route with AngularJS object id

I have an ASP.NET View using server-side #foreaches, now replaced with AngularJS.
Now I use ng-repeat="record in records", and I don't use anymore the #foreach.
The actual code that worked with #record.Id now does not work with {{record.id}}:
<td class="text-nowrap">
<a asp-controller="Records" asp-action="Edit" asp-route-id="{{record.id}}">Edit</a>
<a asp-controller="Records" asp-action="Details" asp-route-id="{{record.id}}">View</a>
<a asp-controller="Records" asp-action="Delete" asp-route-id="{{record.id}}">Delete</a>
</td>
obviously, because the #record.Id was on the server side...
Now, the solution I see it to set something like
However if the controller's route will change it could lead to nowhere... Is there a way to workaround that?
PS.
Some more code for better understanding:
<div ng-app="tablesApp" ng-controller="tablesController as tc">
<table>
<thead>
<tr>
<th>#Html.DisplayNameFor(model => model.Name)</th>
<th>#Html.DisplayNameFor(model => model.Description)</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="record in records">
<td>{{record.name}}</td>
<td>{{record.description}}</td>
<td>
<a asp-controller="Records" asp-action="Edit" asp-route-id="{{record.id}}">Edit</a>
<a asp-controller="Records" asp-action="Details" asp-route-id="{{record.id}}">View</a>
<a asp-controller="Records" asp-action="Delete" asp-route-id="{{record.id}}">Delete</a>
</td>
</tr>
</tbody>
</table>
</div>
JS Controller:
$http.get("/api/Records")
.then(function (response) {
tc.records = response.data;
}));
Actually a little bit better option that the hardcoded route is to use
<a href="#Url.Action(action: "Edit", controller: "Records")/{{record.id}}" ></a>
However this one is supposed to have the {ActionRoute}/{id} fixed structure...
In case you use foreach in razor view (obviously you do) then you can't use angular syntax {{record.id}} you have to use #record.id
But if you get records, as an array/list whatever, in AngularJs then you have to change your html and use ng-repeat
-- Edit
Sorry just see your code again, you used asp-action and asp-controller etc
They are TAG HELPERS from core version, in other words they will get rendered on the server side and what you will get in the browser actually is anchor link like
<a href="/Records/Edit/{{record.id}}" >Edit</a>
AngularJs as you know is client side so it won't render. Either use #Url.Action as you already did or you could remove asp-route-id and add the id later using custom directive.

Trying to open popup through jquery containing html syntax

I'm Trying to open popup through jquery containing html syntax.but not getting proper idea.I have open an alert as shown below ex but how to open this HTML.The example code which i have shared gets data dynamically in mvc and on clicking that hyperlink i want to open an html page which should also contain dynamically data 'Html' code is given below.Any idea would be appreciated.
HTML
<body>
<table>
<tr>
<td>zone</td><td>Date</td>
</tr>
<tr>
<td>CreatedBy</td><td>CreatedDate</td>
</tr>
<tr>
<td>ClosedBy</td><td>ClosedDate</td>
</tr>
<tr>
<td>Pririty</td><td>IssueType</td>
</tr>
<tr>
<td>Branch/Location</td><td>IssueDescription</td>
</tr>
</table>
<select>
<option value="Open">Open</option>
<option value="Closed">Closed</option>
</select>
<textarea>Description</textarea>
<select>
<option value="Open">Open</option>
<option value="Closed">Closed</option>
</select>
<textbox>Attachment</textbox>
<input type="submit" value="submit"/>
</body>
asp.net mvc
<td id="statusdiv_#item.EscId" class="statusdiv">#Html.ActionLink(#Html.DisplayFor(model => item.Status).ToString(), "Escalation")</td>
jquery
$('.statusdiv').click(function () {
alert('hello');
});

dropdownlist button kilter ie and mozilla

I'm having problems with the dropdownlist button.. the buttons looks weird..
Here is the image: http://imgur.com/9zHNM
HTML markup:
<td class="style 4">
<select name="ctl00$ContentPlaceHolder1$ucPromotions1$ddlCompany"
id="ctl00_ContentPlaceHolder1_ucPromotions1_ddlCompany"
style="height:25px;width:167px;">
</td>
CSS markup:
.style4
{
width: 185px;
}
What could be the problem?
Edit: problem resolved, it was the padding of the select in one my CSS
i have resolved it with this style
<td class="style 4">
<select name="ctl00$ContentPlaceHolder1$ucPromotions1$ddlCompany"
id="ctl00_ContentPlaceHolder1_ucPromotions1_ddlCompany"
style="height:25px;width:167px;padding:0 0;padding-top:0;paddingright-:0;padding- bottom:0;padding-left-value:0; ">
</td>
It's kinda hard to help you without a living demo but, what if you adjust the same style on the class .style4 and the style of the select?
Set them both at width: 185px; for example.
Hope it helps!
Your CSS properties in .style4 will not have any effect, because you've set the class attribute value to style 4. Remove the whitespace :)
Btw.: Your HTML has some errors.
Here is the valid one:
<td class="style4">
<select name="ctl00$ContentPlaceHolder1$ucPromotions1$ddlCompany" id="ctl00_ContentPlaceHolder1_ucPromotions1_ddlCompany" style="height:25px;width:167px;">
<option value="one">ONE</option>
<option value="two">TWO</option>
<option value="three">THREE</option>
</select>
</td>
Numbers only for CSS classes and IDs are not allowed.

Categories

Resources