This should not be as hard as it seems to be, but I can't for the life of me create a table in VB using Razor syntax. The following does not work (despite what some examples would lead me to believe):
<table>
#Code
For Each item in Model
#<tr>
#<td>#item.DocumentType</td>
</tr>
Next
End Code
</table>
This gives me the following error:
Parser Error Message: "<" is not valid at the start of a code block.
Only identifiers, keywords, comments, and "(" are valid.
Thanks in advance for the help!
Try removing the # before the <td>:
<table>
#Code
For Each item in Model
#<tr>
<td>#item.DocumentType</td>
</tr>
Next
End Code
</table>
or a bit shorter:
<table>
#For Each item in Model
#<tr>
<td>#item.DocumentType</td>
</tr>
Next
</table>
Once again you must remove the # before the <td>.
<table>
#For Each item in Model
#<tr><td>#item.DocumentType</td></tr>
Next
</table>
See if this code snippet does what you need it to do. This example was taken from the ASP Forums. I think the #<tr> may be what is throwing the loop off, but I have not written VB Razor (only the ASPX version of VB). Also, I just found some additional looping examples on MSDN
Related
Please help, i cann't find in freemarker guide how to convert from thymeleaf this:
lists.isEmpty and for each
<th:block th:if="${#lists.isEmpty(employees)}">
<h3>No employee</h3>
</th:block>
<th:block th:unless="${#lists.isEmpty(employees)}">
<tr th:each="contact,iterStat : ${employees}">
<td th:text="${iterStat.count}"></td>
<td th:text="${contact.name}"></td>
<td th:text="${contact.phone}"></td>
Thanks!
Maybe Something like this? (sketch, not tested)
<#list employees as contact>
<tr>
<td>${contact?index}
<td>${contat.name}</td>
<td>${contact.phone}</td>
</tr>
<#else>
<h3>No employee</h3>
</#list>
Notes
<#list> Will generate a <tr> element for each item in the employees sequence, containing <td>'s for each field.
If the employees sequence is empty it will generate the <h3> element.
See List Directive Doc
It gets the zero based index of the item using the build-in function
?index. See built-ins and loop variables in the help. Freemarker built-ins Doc. If you want one based, you can add one to it.
It's works
<#list employees as contact>
<tr>
<td>${contact?index}
<td>${contat.name}</td>
<td>${contact.phone}</td>
</tr>
<#else>
<h3>No employee</h3>
</#list>
I have a view that is using a model. I just need to do a simple subtraction on the model variables using razor.
Here is what the code looks like:
#model Inquiry.Inq_Weights
<table id="mainWeights">
<tr>
<td>#Html.DisplayFor(model => Model.HotScaleHalfId)</td>
<td>#Html.DisplayFor(model => Model.HotScaleGrossWeight)</td>
<td>#Html.DisplayFor(model => Model.HotScaleTareWeight)</td>
</tr>
<tr>
<td><strong>Total Hot Scale Weight</strong></td>
</tr>
<tr>
<td align="right">(#Model.HotScaleGrossWeight - #Model.HotScaleTareWeight;)</td>
</tr>
</table>
I am trying the (#Model.HotScaleGrossWeight - #Model.HotScaleTareWeight;)
but it is just displaying "0 - 0". The zeros are correct at this point. but i don't want it to display the expression, just the result of that operation.
I have also tried using a variable then listing that, as in
#{
var netWeight = #Model.HotScaleGrossWeight - #Model.HotScaleTareWeight;
netWeight;
}
But that doesn't work either. How can I do simple math on model members?
You should do this:
#(Model.HotScaleGrossWeight - Model.HotScaleTareWeight)
With your other example:
#{
var netWeight = Model.HotScaleGrossWeight - Model.HotScaleTareWeight;
}
Then use it with #netWeight. Please note that the # symbol is razor specific, you don't have prefix your variables with it inside a c# expression. When you write # you are actually saying that you are going to write a c# expression. Writing # before Model is just for the razor engine to know that this is going to be a c# expression (your variable actually) and not a simple text 'Model'.
But I recommend to do this kind of stuff within your controller.
update
as Alexei wrote in comment # is not just for razor: What does the # symbol before a variable name mean in C#?
I am working on a Rails 3.2.11 app using angular 1.0.5.
Currently, a user will select a Cycle from a dropdown, and that will return a bunch of JSON from my controller using ng-resource.
Here is the method
$scope.update = function(cycleId) {
Cycle.get({action: cycleId}, function(resource) {
$scope.selectedCycle = resource;
$scope.tasks = resource.tasks;
$scope.newTask = {cycle_id: resource.cycle.id};
});
};
Here is an example of what json my controller is returning, which is 'resource' in above function: https://gist.github.com/anonymous/01ffe5a37e370661f6fb
Basically I am needing to use ng-repeat twice (one of them nested) using angulars ng-repeat, so that I can get the task_type_name in there as a header. I'm getting some weird interesting results. See the shorted code in my view below and the full thing here
<section ng-repeat="(task_type_name,task_type) in tasks ">
<h2>{{task_type_name}}</h2>
<table>
<tr>
<th>Task Name</th>
</tr>
<section id="task-edit">
<tr ng-repeat="task in task_type">
<td>
<%= link_to "{{task.name}}", '', "ng-click"=>"toggleShowHistory(task.id)" %>
</td>
</tr>
</section
</table>
So my is occuring at this part here
<section id="task-edit">
<tr ng-repeat="task in task_type">
If I try to combine that section and tr, OR change tr to ANYTHING but a tr, {{task}} no longer becomes available.
<section class="task-edit" ng-repeat="task in task_type">
{{task}} is available right here
<tr>
{{task}} is not available right here
<td>
{{task}} is not avaiable right here
</td>
</tr>
</section>
I tested the same concept on the first loop, and it seems to be fine on that loop just not the second, nested loop.
I'm assuming it has something to do with the scope. But i'm just not getting it.
Also, if you have any tips, i'm very new to angular and would love them.
I created a demo, and I am not seeing any issue. Please check your data source and make sure you plug in the tasks value of the json.
You need to change the nested section to tbody.
Demo on jsfiddle
I have the following table structure inside a view which gets displayed in the _Layout view in place of #RenderBody
<table>
<thead>
<tr>
<th>first</th>
<th>second</th>
<th>third</th>
</tr>
</thead>
<tbody>
<tr>
<td>1st</td>
<td>2nd</td>
<td>3rd</td>
</tr>
</tbody>
</table>
In my _Layout page, I want to apply the contextMenu event to the th elements, however, being a beginner, I'm having a hard time figuring the selector for the same.
Some combinations that I've tried -
I have a reference to my table in a variable called oTable
oTable.$('tr th').contextMenu ....
oTable.$('thead tr th').contextMenu ....
$('table.tableID th').contextMenu ....
None of them are working. Any suggestions?
If you simply want to select ALL of your th elements then you don't need anything more complicated than this:
$('th').contextMenu ....
If your table has an id associated to it then the following will allow you to target just that table:
$('#yourid th')
Hi Im writing a cucumber feature to verify a table using capybara finder(not tableish). I followed dennisreimann tutorial and it works fine when there is no td colspan. It thrown IndexError when td has colspan. Has anyone managed to overcome this problem?I guess colspan breaks the 2d array structure that is passed into the diff! function. Any suggestion or hint would be much appreciated. Thanks
Example of table:
<table id="mytable">
<tbody>
<tr>
<th>header</th>
<td colspan="5">Value1</td>
...
</tr>
</tbody>
</table>
Code example from tutorial:
rows = find("table#mytable").all('tr')
table = rows.map { |r| r.all('th,td').map { |c| c.text.strip } }
expected_table.diff!(table)
Ok So I found the confirmation that it's not working here. The assumption is the number of cell in each row is the same hence colspan breaks it