View action link is not passing values to controller actions - asp.net-mvc-views

I have the following view:
<h2>
Contract</h2>
#Using Html.BeginForm()
#Html.ValidationSummary(False)
#<fieldset>
<legend>Hire Contract</legend>
<div class="editor-label">
#Html.LabelFor(Function(model) model.ContractNo)
</div>
<div class="editor-field">
#Html.DisplayTextFor(Function(model) model.ContractNo)
</div>
<div class="editor-label">
#Html.LabelFor(Function(model) model.HireId)
</div>
<div class="editor-field">
#Html.DisplayTextFor(Function(model) model.HireId)
</div>
-- More fields here ---
<div>
<table>
<tr>
<th>
Line Id
</th>
<th>
Description
</th>
<th>
Return Quantity
</th>
<th>
</th>
</tr>
<p/>
#Html.ActionLink("Add Line", "AddContractLine")
<p/>
#For Each item In Model.HireContractLines
Dim currentItem = item
#<tr>
<td>
#Html.DisplayFor(Function(modelItem) currentItem.LineId)
</td>
<td>
#Html.DisplayFor(Function(modelItem) currentItem.Description)
</td>
-- Many other fields here ...
<td>
#Html.ActionLink("Edit", "EditContractLine", New With {.id = currentItem.LineId})
|
#Html.ActionLink("Delete", "DeleteContractLine", New With {.id = currentItem.LineId})
|
#Html.ActionLink("Return Line", "ReturnContractLine", New With {.id = currentItem.LineId})
</td>
</tr>
Next
</table>
</div>
<p>
<input type="submit" value="Full Return" />
</p>
</fieldset>
And the controller looks like:
Function EditContractLine(hireLineId? As Integer) As ActionResult
Dim contractLine = GetContractLine(CInt(hireLineId))
Return View(ContractLine)
End Function
However, when I click on Edit Line or Delete Line the value is not passed to controller action. It is always Null.
Can anyone please point me to the issue? Any comments will be appreciated.

I found what the problem was:
Parameter name should be same in the Action Link and the Controller Parameter.
eg .id should be .hireLineId to match the controller parameter name!!
#Html.ActionLink("Return Line", "ReturnContractLine", New With {.id = currentItem.LineId})

Related

Get ID from item which is checked from checkbox in ASP.NET Core 5 MVC

I need help!
I have an ASP.NET Core 5 MVC Webapplication. I have a list with items from a .mdf-database and want a checkbox at the end of each item-row. When I am in the controller of this view, I want to have the ID of the item, which is checked. There could be more than one checked. But I don't know how to to this.
Below some snippets from my code:
Index.cshtml
<form asp-action="Send">
<table class="table">
<thead>
<tr>
<th>
#Html.DisplayNameFor(model => model.Id)
</th>
<th>
#Html.DisplayNameFor(model => model.Bez)
</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.Id)
</td>
<td>
#Html.DisplayFor(modelItem => item.Bez)
</td>
<td>
<a asp-action="Edit" asp-route-id="#item.Id">Edit</a> |
<a asp-action="Delete" asp-route-id="#item.Id">Delete</a>
</td>
<td>
#Html.CheckBox("Finalized", false)
</td>
</tr>
}
</tbody>
</table>
<input type="submit" value="Send" class="btn btn-primary" />
<br /><br />
<p>Achtung! Beim Senden an einem Freitag wird der Dienstplan automatisch für den darauffolgenden Montag eingeteilt.</p>
</form>
Can someone help me? I just want the id's in a list in my controller, which are checked.
It seems you want to post the selected Ids to backend. Here is a working demo you could follow:
#Html.CheckBox("Finalized", false,new { #value=item.Id})
Controller:
[HttpPost]
//if the type of item.Id is int, it will receive int array in backend
public IActionResult Send(int[] Finalized)
{
//do your stuff...
}

Selenium Webdriver Python clicking radio button is showing WebElement object is not callable

I am trying to click on a radio button on a webpage which I am automating in Selenium Webdriver Python.
When my code tries to click on the radio button it is showing the error:
TypeError: 'WebElement' object is not callable:
The full error is:
Traceback (most recent call last):
File "C:\Webdriver\ClearCore\TestCases\MatchConfigrationPage_TestCase.py", line 85, in test_add_match_configuration_possibles_name
possibles_match_rules_tab.click_selected_rule_radio_button("Name")
File "C:\Webdriver\ClearCore\Pages\match_rules_tab.py", line 82, in click_selected_rule_radio_button
radio_button = self.driver.find_element(By.XPATH, '//table[#id="match_configuration_add_possible_tab_match_rules_ct_mapping_body"]//span[#title="Name" and contains(text(), "Name")]//ancestor::tr[1]//input[#type="radio"]')
TypeError: 'WebElement' object is not callable
I can find the button using the following XPATH in Firefox XPATH checker.
//table[#id="match_configuration_add_possible_tab_match_rules_ct_mapping_body"]//span[#title="Name" and contains(text(), "Name")]//ancestor::tr[1]//input[#type="radio"]
My method to call the button and click is as follows:
from selenium.webdriver.common.by import By
def click_selected_rule_radio_button(self, name):
# params name: The name of the data object to be selected for the match rule, e.g. Name, Address
radio_button = self.driver.find_element(By.XPATH, '//table[#id="match_configuration_add_possible_tab_match_rules_ct_mapping_body"]//span[#title="%s" and contains(text(), "%s")]//ancestor::tr[1]//input[#type="radio"]' (name, name))
self.driver.execute_script("arguments[0].click()", radio_button)
return self
the name parameter in the method it's value is "Name", %s in the code has the value "Name"
I have also tried the following:
def click_selected_rule_radio_button2(self, name):
# params name: The name of the data object to be selected for the match rule, e.g. Name, Address
#WebDriverWait(self.driver, 20).until(EC.presence_of_all_elements_located((By.ID, 'match_configuration_add_possible_tab_match_rules_ct_mapping_body')))
radio_button = WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.XPATH, '//table[#id="match_configuration_add_possible_tab_match_rules_ct_mapping_body"]//span[#title="Name" and contains(text(), "Name")]//ancestor::tr[1]//input[#type="radio"]')))
radio_button.click()
return self
From my TestCase class i call the method as follows:
possibles_match_rules_tab.click_selected_rule_radio_button("Name")
code snippet of test case is as follows:
def test_add_match_configuration_possibles_name(self):
print "*** Test add Match Configuration Possibles - Name ***"
projectNavigator = project_navigator.ProjectNavigatorPage(self.driver)
possiblesPage = projectNavigator.select_projectNavigator_item("Possibles") # click Possibles from project navigator
possiblesPage.click_add_possibles_button()
possiblesPage.enter_possible_matches_name_and_description_from_details_tab("name_dob", "date of birth possible match rule")
possibles_match_rules_tab = possiblesPage.click_match_rules_tab()
possibles_match_rules_tab.click_possibles_match_rules_add_button()
possibles_match_rules_tab.enter_match_rule_name("name_dob")
possibles_match_rules_tab.click_selected_rule_radio_button("Name")
The HTML is:
<table id="match_configuration_add_possible_tab_match_rules_ct_mapping_body" cellspacing="0" style="table-layout: fixed; width: 100%;">
<colgroup>
<tbody>
<tr class="GPI5XK1CFG" __gwt_subrow="0" __gwt_row="0">
<td class="GPI5XK1CEG GPI5XK1CGG GPI5XK1CHG">
<div __gwt_cell="cell-gwt-uid-339" style="outline-style:none;" tabindex="0">
<input type="radio" name="rbCrossRow2" />
</div>
</td>
<td class="GPI5XK1CEG GPI5XK1CGG">
<div __gwt_cell="cell-gwt-uid-340" style="outline-style:none;">
<span class="" title="Name" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Name</span>
</div>
</td>
<td class="GPI5XK1CEG GPI5XK1CGG GPI5XK1CBH">
<div __gwt_cell="cell-gwt-uid-341" style="outline-style:none;">
<input id="match_configuration_add_possible_tab_match_rules_cb_name" type="checkbox" />
</div>
</td>
</tr>
<tr class="GPI5XK1CEH" __gwt_subrow="0" __gwt_row="1">
<td class="GPI5XK1CEG GPI5XK1CFH GPI5XK1CHG">
<div __gwt_cell="cell-gwt-uid-339" style="outline-style:none;">
<input type="radio" name="rbCrossRow2" />
</div>
</td>
<td class="GPI5XK1CEG GPI5XK1CFH">
<div __gwt_cell="cell-gwt-uid-340" style="outline-style:none;">
<span class="" title="Address" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Address</span>
</div>
</td>
<td class="GPI5XK1CEG GPI5XK1CFH GPI5XK1CBH">
</tr>
<tr class="GPI5XK1CFG" __gwt_subrow="0" __gwt_row="2">
<tr class="GPI5XK1CEH" __gwt_subrow="0" __gwt_row="3">
</tbody>
Can anyone see what is wrong, why the radio button is not callable, it will not click it?
Thanks,
Riaz
You can use JavaScript to click radio button.Code is as follow:
driver=webdriver.Chrome('./chromedriver.exe')
driver.get('your URL')
time.sleep(10)
radioButton = driver.find_element_by_xpath("Radio Button Xpath") #like //input[#id='female']
driver.execute_script("arguments[0].click();", radioButton)
#driver.quit()

I have a table of rows with checkboxes in columns. How do i select a particular checkbox

I have the following HTML structure. A table with rows, the 2nd column has the text displayed e.g. Title (in row 1), FName (in row 2), SNAME (in row3), GENDER etc.
The 3rd column has a checkbox for each row.
I am trying to select a particular checkbox. E.g. my method will accept a parameter (the name of the text value in the row e.g. TITLE).
The method will select the checkbox for TITLE.
When i call the method again with parameter FNAME, the checkbox for FNAME will be clicked.
I am using Selenium Webdriver with Python
I have tried the following XPATH to identify the checkbox:
//span[#title="TITLE" and contains(text(), "TITLE")]/following-sibling::*
//span [text()="TITLE"]/../../preceding-sibling::td/div/input[#type="checkbox"]
These do not find the checkbox for the row called TITLE
I can get to the TITLE with the following XPATH.
//span [text()="TITLE"]
My code snippet is:
def add_mapping2(self, name):
try:
checkbox = self.driver.find_element(By.XPATH, '//span [text()="+name+"]/../../preceding-sibling::td/div/input[#type="checkbox"]')
checkbox.click()
except NoSuchElementException, e:
return False
return True
From my unittest.Testcase class I call the method as follows:
class MappingsPage_TestCase(BaseTestCase):
def test_add_mappings(self):
mappingsPage = projectNavigator.select_projectNavigator_item("Mappings")
mappingsPage.add_mapping2("TITLE")
mappingsPage.add_mapping2("SNAME")
The HTML is:
<table id="data_configuration_edit_mapping_tab_mappings_ct_mapping_body" cellspacing="0" style="table-layout: fixed; width: 100%;">
<colgroup>
<tbody>
<tr class="GOFU2OVFG" __gwt_subrow="0" __gwt_row="0">
<tr class="GOFU2OVEH GOFU2OVGH GOFU2OVPG GOFU2OVMG" __gwt_subrow="0" __gwt_row="1">
<td class="GOFU2OVEG GOFU2OVFH GOFU2OVHG GOFU2OVHH GOFU2OVAH GOFU2OVNG">
<td class="GOFU2OVEG GOFU2OVFH GOFU2OVHH GOFU2OVAH GOFU2OVNG">
<div __gwt_cell="cell-gwt-uid-792" style="outline-style:none;">
<span title="TITLE" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">TITLE</span>
</div>
</td>
<td class="GOFU2OVEG GOFU2OVFH GOFU2OVHH GOFU2OVBH GOFU2OVOG GOFU2OVAH GOFU2OVNG">
<div __gwt_cell="cell-gwt-uid-793" style="outline-style:none;" tabindex="0">
<input type="checkbox" checked="" tabindex="-1"/>
</div>
</td>
</tr>
<tr class="GOFU2OVFG" __gwt_subrow="0" __gwt_row="2">
<td class="GOFU2OVEG GOFU2OVGG GOFU2OVHG">
<div __gwt_cell="cell-gwt-uid-791" style="outline-style:none;">
<input type="radio" name="rbCrossRow124"/>
</div>
</td>
<td class="GOFU2OVEG GOFU2OVGG">
<div __gwt_cell="cell-gwt-uid-792" style="outline-style:none;">
<span class="" title="FNAME" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">FNAME</span>
</div>
</td>
<td class="GOFU2OVEG GOFU2OVGG GOFU2OVBH">
<div __gwt_cell="cell-gwt-uid-793" style="outline-style:none;">
<input type="checkbox" tabindex="-1"/>
</div>
</td>
</tr>
<tr class="GOFU2OVEH" __gwt_subrow="0" __gwt_row="3">
<tr class="GOFU2OVFG" __gwt_subrow="0" __gwt_row="4">
<tr class="GOFU2OVEH" __gwt_subrow="0" __gwt_row="5">
<tr class="GOFU2OVFG" __gwt_subrow="0" __gwt_row="6">
more rows with names with checkboxes etc......
</tbody>
</table>
What XPATH could I use to get the checkbox for TITLE, FNAME etc?
I have the table ID "data_configuration_edit_mapping_tab_mappings_ct_mapping_body"
Maybe there is a way to start from the table ID and use a for loop to iterate through the rows and find the particular checkbox?
Thanks.
Riaz
you would use the following xpath expression
String xpath = "//span[#title = 'TITLE']/ancestor::tr[1]//input[#type = 'checkbox']"
What it does:
first search for a span element with your parameter (pls change 'TITLE' to the variable you are using)
then find the first ancestor element that is a tr-element
from there find the input element that is your checkbox within this tr-element
You could then refine to sth like this:
WebElement table = driver.findElement(By.id("data_configuration_edit_mapping_tab_mappings_ct_mapping_body"));
WebElement checkbox = table.findElement(By.xpath(xpath));
For the interest of others whom come across a similar problem. My Python code which I have used for the above answer is:
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
def add_mapping(self, name):
wait = WebDriverWait(self.driver, 10)
try:
checkbox = wait.until(EC.element_to_be_clickable((By.XPATH, '//span[#title = "%s"]/ancestor::tr[1]//input[#type = "checkbox"]' % name)))
#table_id = self.driver.find_element(wait.until(EC.element_to_be_clickable(By.ID, 'data_configuration_edit_mapping_tab_mappings_ct_mapping_body')))
#checkbox = table_id.find_element(By.XPATH, '//span[#title = "TITLE"]/ancestor::tr[1]//input[#type = "checkbox"]')
checkbox.click()
except NoSuchElementException, e:
return False
return True
The table id i commented out also works.

The argument "each" was registered with type "array", but is of type "string" in view helper

Im trying to make a typo3 extension and i want to show all relations(in this case cities) from region. I connected them in them in the kickstarter like this:
i tried to print the cities in the regions single view doing this:
<table class="tx-collection-plan" >
<tr>
<td>
<f:translate key="tx_collectionplan_domain_model_region.name" />
</td>
<td>
{region.name}
</td>
</tr>
<tr>
<td>
<f:translate key="tx_collectionplan_domain_model_region.cities" />
</td>
<td>
<ul>
<f:for each="{region.cities)" as="city">
<li>{city.name}</li>
</f:for>
</ul>
</td>
</tr>
</table>
But i keep getting this error:
Oops, an error occurred!
The argument "each" was registered with type "array", but is of type "string" in view helper "TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper"
is there another solution to show all subparts of a region (with links that can be klicked -> like the list view of cities itself)?
EDIT: when i remove the for loop and just print city.name, i only get
the dot from li .... but nothing else
I found the solution:
all i need is
<table class="tx-collection-plan" >
<tr>
<td>
<f:translate key="tx_collectionplan_domain_model_region.name" />
</td>
<td>
{region.name}
</td>
<td>
<f:for each="{region.cities}" as="city">
{city.name}
</f:for>
</td>
</tr>
</table>
the <f:translate> was unnecessary

Emberjs CollectionView array in an array

Hi I would like to know if it was possible to use a more complex array for the collectionView.
Because for now I'm only using it like this :
App.GroupList = Ember.ArrayController.create({
content: ['A','B','C','D'],
})
App.GroupListView = Ember.CollectionView.extend({
tagName: 'tbody',
contentBinding: "App.GroupList"
})
And display them like this :
<table class="table-history">
{{#collection App.GroupListView}}
<td class="col-left">
{{view.content}}
</td>
<td>
<span class="col-number-contact">0</td>
</td>
<td>
<div class="ph-img"></div>
</td>
<td>
<div class="ed-img"></div>
</td>
{{/collection}}
</table>
So far, so good, its working well, but I would like to add more information inside the content like this :
content: [
['A','1'],
['B','2'],
['C','3'],
]
And display the number in a second <td> tad (the one with the 0 inside).
But its not working.. and I wouldn't even know how to display them in my template.
Someone already managed to passe a complex collection content ?
You can use an array of objects instead like this:
App.GroupList = Ember.ArrayController.create({
content: [{'id':1,val:'A'},{'id':2,val:'B'},{'id':3,val:'C'},{'id':4,val:'D'}];
});
Then in your template, you can access it like this:
<table class="table-history">
{{#collection App.GroupListView}}
<td class="col-left">
{{view.content.val}}
</td>
<td>
<span class="col-number-contact">{{view.content.id}}</td>
</td>
<td>
<div class="ph-img"></div>
</td>
<td>
<div class="ed-img"></div>
</td>
{{/collection}}
</table>