Create a razor view dynamically for below database rows - asp.net-mvc

for BELOW table TechCourse contains courseName image and price I need to display these details dynamically using BELOW CShtml code. for each course, that above div code should display dynamically.
+------------+-----------+---------------------+-------------+--+
| | | | | |
| Course_ID | Name | imageurl | courseprize | |
| 100 | Physics | /images/physics.jpg | 750 | |
| 101 | Maths | /images/maths.jpg | 800 | |
| 102 | Biology | /images/bio.jpg | 800 | |
| 103 | Chemistry | images/chem.jpg | NULL | |
+------------+-----------+---------------------+-------------+--+
Div Code:
<section class="popular-posts-block container">
<header class="popular-posts-head">
<h2 class="popular-head-heading">Most Popular Courses</h2>
</header>
<div class="row">
<div class="slider popular-posts-slider">
#foreach (var TechCourse in Model)
{
<div>
<div class="col-xs-12">
<!-- popular post -->
<article class="popular-post">
<div class="aligncenter">
<img src
Here Course Image
alt="image description">
</div>
<div>
<strong class="bg-primary text-white font-lato text-uppercase price-tag">$99.00</strong>
</div>
<h3 class="post-heading">CourseName</h3>
<div class="post-author">
<div class="alignleft rounded-circle no-shrink">
<a href="instructor-single.html">
Here Image
<img src="http://placehold.it/35x35" class="rounded-circle" alt="image description"></a>
</div>
<h4 class="author-heading">Arfat</h4>
</div>
<footer class="post-foot gutter-reset">
<ul class="list-unstyled post-statuses-list">
<li>
<a href="#">
<span class="fas icn fa-users no-shrink"><span class="sr-only">users</span></span>
<strong class="text fw-normal">98</strong>
</a>
</li>
<li>
<a href="#">
<span class="fas icn no-shrink fa-comments"><span class="sr-only">comments</span></span>
<strong class="text fw-normal">10</strong>
</a>
</li>
</ul>
<ul class="star-rating list-unstyled">
<li><span class="fas fa-star"><span class="sr-only">star</span></span></li>
<li><span class="fas fa-star"><span class="sr-only">star</span></span></li>
<li><span class="fas fa-star"><span class="sr-only">star</span></span></li>
<li><span class="fas fa-star"><span class="sr-only">star</span></span></li>
<li><span class="fas fa-star"><span class="sr-only">star</span></span></li>
</ul>
</footer>
</article>
</div>
</div>
}
</div>
</div>
</section>
for the above table, TechCourse contains courseName image and price I need to display these details dynamically using above cshtml code. for each course, that above div code should display dynamically.

Use the code below:
public ActionResult Index()
{
var coursetab = (from list in dbcontext.Course_master orderby list.CreatedDate descending where list.Course_ID != 0 select list).ToList();
return View(coursetab);
}
ViewCode:
<section class="popular-posts-block container">
<header class="popular-posts-head">
<h2 class="popular-head-heading">Most Popular Courses</h2>
</header>
<div class="row">
<!-- popular posts slider -->
<div class="slider popular-posts-slider">
#foreach (var item in Model)
{
<div>
<div class="col-xs-12">
<!-- popular post -->
<article class="popular-post">
<div class="aligncenter">
<img src="~/Images/CourseImages/#item.Imageurl" style="height:147px;" />
</div>
<div>
<strong class="bg-primary text-white font-lato text-uppercase price-tag"></strong>
</div>
<h3 class="post-heading">#item.Name</h3>
<div class="post-author">
<div class="alignleft no-shrink rounded-circle">
<img src="http://placehold.it/35x35" class="rounded-circle" alt="image description">
</div>
<h4 class="author-heading">Arfat</h4>
</div>
</article>
</div>
</div>
}
</div>
</div>
</section>

Related

Masonry not working with bootstrap 5 and angular 13

I have freshly implemented masonry on my website(https://mypleaks.com) along bootstrap 5 and angular 13.
I have referred example from https://getbootstrap.com/docs/5.1/examples/masonry/ and added <script src="https://cdn.jsdelivr.net/npm/masonry-layout#4.2.2/dist/masonry.pkgd.min.js" integrity="sha384-GNFwBvfVxBkLMJpYMOABq3c+d3KnQxudP/mGPkzpZSTYykLBNsZEnG2D9G/X/+7D" crossorigin="anonymous" async></script>
I have created cards dynamically like below :
<div class="container-lg content-container mt-lg-5 pr-lg-3 pl-lg-3 pt-lg-2 mt-3 p-0">
<div class="row" data-masonry='{"percentPosition": true }' style="position: relative; height: 1068px;">
<div class="col-sm-6 col-lg-4 mb-4" *ngFor="let content of contentList">
<div class="card" [class.remove-card-border]="content.contentType === advertisement">
<img *ngIf="content.attachments" [src]="content.attachments[0].identifier" class="card-img-top">
<div *ngIf="content.contentType != advertisement" class="card-body">
<h5 class="card-title">{{ content.title }}</h5>
<p class="card-text">{{ content.contentText }} <a [href]="content.externalUrl" class="text-nowrap" target="_blank">read more</a></p>
<div class="btn-toolbar d-flex justify-content-center" role="toolbar" aria-label="Toolbar with button groups">
<div class="btn-group mr-3 input-group" role="group" aria-label="First group" ngbTooltip="good enough, people should know">
<button type="button" [disabled]="evaluationClicked" class="btn btn-success" placement="top"
(click)="upVote(content); evaluationClicked = true;"><i class="fa fa-thumbs-up" aria-hidden="true"></i></button>
<div class="input-group-prepend">
<div class="input-group-text">{{content.promoteCount}}</div>
</div>
</div>
<div class="btn-group ml-3 input-group" role="group" aria-label="Second group" ngbTooltip="fake or not good enough">
<div class="input-group-prepend">
<div class="input-group-text">{{content.rejectCount}}</div>
</div>
<button type="button" [disabled]="evaluationClicked" class="btn btn-danger" placement="top"
(click)="downVote(content); evaluationClicked = true;"><i class="fa fa-thumbs-down fa-flip-horizontal" aria-hidden="true"></i></button>
</div>
</div>
</div>
<div *ngIf="content.contentType === advertisement" class="d-flex justify-content-center">
<app-google-ads></app-google-ads>
</div>
</div>
</div>
</div>
</div>
Somehow, Style not updating on myPleaks similar to bootstrap example, Refer below snippets
bootstrap example
Thanks in advance for any help.
Instead using masonry-layout directly, I used ngx-masonry. Following are the package.json dependencies. And refer the documentation here
"masonry-layout": "^4.2.2",
"ngx-masonry": "^13.0.0"
Add following modules in app.module.ts
Wrap dynamic code in tag <ngx-masonry [options]="myOptions"> and add following config in the component implementation.
public myOptions: NgxMasonryOptions = {
gutter: 10};

Thymeleaf start new row every n elements

So I am trying to create a Thymeleaf loop where have a list of n elements. Every fourth (starting at the first) I create a parent element, and each one gets added to that until a new parent is created.
So the idea is
for e : elements {
if index % 4 = 0 {
create new parent
}
add e to parent
}
I am trying to implement this in Thymeleaf and cannot get anything working. Here is the closest I think I have gotten (that inner loop causes "IllegalStateException: No index"):
<div th:each="metric, rowStatus : ${metrics}"
class="row tile_count" th:if="${rowStatus.index % 4} == 0">
<div th:each="i: ${#numbers.sequence(rowStatus.index , rowStatus.index +4)}"
th:replace="layouts/template.html :: metricCard(name=${metrics[i].name}, value=${metrics[i].value},description=${metrics[i].description}, severity=${metrics[i].severity})"></div>
</div>
The desired html is something in the ball park of:
<div class="row tile_count">
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
<span class="count_top"><i class="fa fa-user"></i> Total HR1 Files</span>
<div class="count">17</div>
<span class="count_bottom"><i class="green"><i class="fa"></i></i> Same as last Week</span>
</div>
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
<span class="count_top"><i class="fa fa-user"></i> Total Transactions</span>
<div class="count green"> 7,353</div>
<span class="count_bottom"><i class="green"><i class="fa fa-sort-asc"></i>34% </i> From last Week</span>
</div>
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
<span class="count_top"><i class="fa fa-clock-o"></i> Average Processing Time</span>
<div class="count">43 sec</div>
<span class="count_bottom"><i class="green"><i class="fa fa-sort-asc"></i>3% </i> From last Week</span>
</div>
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
<span class="count_top"><i class="fa fa-user"></i> Total Failed Transactions</span>
<div class="count">0</div>
<span class="count_bottom"><i class="red"><i class="fa fa-sort-desc"></i>12% </i> From last Week</span>
</div>
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
<span class="count_top"><i class="fa fa-user"></i> Total Loaded Transactions</span>
<div class="count">7,353</div>
<span class="count_bottom"><i class="green"><i class="fa fa-sort-asc"></i>21% </i> From last Week</span>
</div>
</div>
<div class="row tile_count">
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
<span class="count_top"><i class="fa fa-user"></i> Total HR2 Files</span>
<div class="count">05</div>
<span class="count_bottom"><i class="green"><i class="fa"></i></i> Same as last Week</span>
</div>
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
<span class="count_top"><i class="fa fa-user"></i> Total Transactions</span>
<div class="count green">5,421</div>
<span class="count_bottom"><i class="green"><i class="fa fa-sort-asc"></i>10% </i> From last Week</span>
</div>
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
<span class="count_top"><i class="fa fa-clock-o"></i> Average Processing Time</span>
<div class="count">10 sec</div>
<span class="count_bottom"><i class="green"><i class="fa fa-sort-asc"></i>3% </i> From last Week</span>
</div>
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
<span class="count_top"><i class="fa fa-user"></i> Total Failed Transactions</span>
<div class="count">2</div>
<span class="count_bottom"><i class="red"><i class="fa fa-sort-desc"></i>12% </i> From last Week</span>
</div>
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
<span class="count_top"><i class="fa fa-user"></i> Total Loaded Transactions</span>
<div class="count">5,419</div>
<span class="count_bottom"><i class="green"><i class="fa fa-sort-asc"></i>10% </i> From last Week</span>
</div>
</div>
You can try th:remove like this:
<th:block th:each="metric, iterStat : ${metrics}">
<div class="row tile_count" th:remove="${iterStat.index % 4 == 0 ? none : tag}">
<div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
...
</div>
</div>
</th:block>
You can also try the following:
<div class="row pt-5" th:remove="${status.index%4 == 0} ? none : tag">
<div class="col">...</div>
<th:block th:if="${status.index eq 4}" th:utext="'</div>'" />
I used this, cause the remove "tag" feature don't delete the closing div from my row.

wp-bootstrap-nav walker collapse is not working on ipad

Bootstrap navbar collapse is not working. The issue is that it shows a collapsing menu but on click, it is not collapsed.
I have provided my full code so that it can help you to suggest or help me to sort out the issue
<header class="head-image">
<nav id="nav-top" class="navbar hidden-xs hidden-sm" style="margin-bottom: 0px;">
<div class="container text-center">
<div class="col-md-4 col-md-offset-8">
<div class="search-box">
<?php echo do_shortcode('[smart_search id="1"]'); ?>
</div>
</div>
</div>
</nav>
<section id="main-header">
<div class="container">
<div class="pull-left">
<a href="<?php echo esc_url(home_url('/')); ?>" title="<?php echo esc_attr(get_bloginfo('name', 'display')); ?>" rel="home">
<img src="<?php header_image(); ?>" width="213" height="117" alt="">
</a>
</div>
<div class="pull-right hidden-xs hidden-sm">
<div class="row text-right">
<div class="col-xs-12">
<span class="text-white">Order hotline</span>
</div>
<div class="col-xs-12">
<span class="nav-phone">
<i class="fa fa-phone" aria-hidden="true"></i>
<a class="text-white nav-phone" href="tel:+"></a>
</span>
</div>
</div>
<div class="row n-m hidden-xs hidden-sm">
<div class="col-sm-6 col-xs-12 border-brown relative">
<div class="col-xs-3">
<i class="fa fa-user" aria-hidden="true"></i>
</div>
<div class="col-xs-9">
<div class="row">
Login/Register </div>
<div class="row ">
<span class="text-white">
My Account
</span>
</div>
</div>
</div>
<div class="col-sm-5 col-xs-12 border-brown relative">
<div class="col-xs-3">
<a href="<?php echo wc_get_cart_url(); ?>">
<i class="fa fa-shopping-bag" aria-hidden="true"></i>
</a>
</div>
<div class="col-xs-9">
<div class="row">
Shopping bag
</div>
<div class="row">
<span class="text-white">
<?php echo WC()->cart->get_cart_contents_count(); ?> Items <span class="price">(<?php echo WC()->cart->get_cart_total(); ?>)
</span>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<nav class="navbar" id="main-menu">
<div class="container">
<div class="navbar-header hidden-md hidden-lg">
<div class="col-xs-6">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="text-white hidden-lg hidden-md" data-toggle="collapse" data-target="#main-menu-collapse">Menu</span>
</div>
<div class="col-xs-6 pull-right border-brown text-center hidden-lg hidden-md relative">
<div class="row">
<div class="col-xs-4">
<i class="fa fa-shopping-bag" aria-hidden="true"></i>
</div>
<div class="col-xs-8 text-white">
<span class="text-white">
<?php echo WC()->cart->get_cart_contents_count(); ?> Items
<span class="text-white">
(<?php echo WC()->cart->get_cart_total(); ?>)
</span>
</span>
</div>
</div>
</div>
</div>
<div id="main-menu-collapse" class="collapse navbar-collapse">
<?php
wp_nav_menu(array(
'theme_location' => 'primary',
'depth' => 2,
'container' => 'div',
'menu_class' => 'nav navbar-nav',
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
'walker' => new WP_Bootstrap_Navwalker(),
));
?>
<div class="row border-top hidden-lg hidden-md">
<div class="col-xs-3">
Contact
</div>
<div class="col-xs-9">
<a href="tel:">
<i class="fa fa-phone" aria-hidden="true"></i>
<span class="text-white"></span>
</a>
</div>
</div>
<div class="row border-top hidden-lg hidden-md">
<div class="col-xs-3">
Login/ register
</div>
<div class="col-xs-9">
<a href="<?php echo get_permalink(get_option('woocommerce_myaccount_page_id')); ?>">
<i class="fa fa-user" aria-hidden="true"></i>
<span class="text-white">My account</span>
</a>
</div>
</div>
</div>
</div>
</nav>
<nav class="navbar" id="menu-shortcut">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav col-lg-12 text-center">
<li class="col-lg-4 col-md-4 text-left">text</li>
<li class="col-lg-4 col-md-4">text</li>
<li class="col-lg-4 col-md-4 text-right"><a class="toggle-modal" href="javascript:void(0);">Sign up </a></li>
</ul>
</div>
</div>
</nav>
</header>
I am also using Jquery the code is below, there is no jquery conflict in my code everything working perfectly only getting the issue when I am browsing form iPad
$('#main-menu .navbar-header .col-xs-6:first-child, #main-menu .navbar-header button').click(function()
{
if($(this).children('button').attr('class') == "navbar-toggle collapsed")
{
$(this).parents('.container').children('#main-menu-collapse').addClass('in');
$(this).parents('.container').children('#main-menu-collapse').slideDown('fast', function() {
});
$(this).children('button').html("");
$(this).children('button').css({
'min-width' : '44px',
'min-height' : '34px'
});
$(this).children('button').attr('aria-expanded', 'true');
$(this).children('button').removeClass('collapsed');
}else
{
$(this).children('button').addClass('collapsed');
$(this).parents('.container').children('#main-menu-collapse').slideDown('fast', function() {
});
$(this).parents('.container').children('#main-menu-collapse').css('display', 'none');
$(this).children('button').attr('aria-expanded', 'false');
$(this).parents('.container').children('#main-menu-collapse').removeClass('in');
$(this).children('button').css({
"margin-top" : "11px",
'background' : 'none'
});
$(this).children('button').html('<span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span>');
}
});
.click() does not happen in Safari unless the element it is bound on is a legitimate click event receiver (target) in Apple's own implementation of web standard (which differs from current web standard).
The simplest way to make any element become a "legitimate" click event target is to add
cursor: pointer;
to it.
Other workarounds include using different events, such as touchstart, tap or input, depending on case.
So, in your case, a fix would be to add this to your CSS:
#main-menu .navbar-header .col-xs-6:first-child,
#main-menu .navbar-header button {
cursor: pointer;
}
Or to change the wrapper to:
$('#main-menu .navbar-header .col-xs-6:first-child, #main-menu .navbar-header button')
.on('click touchstart', function(){
// your code here
})
In my opinion, you should remove wordpress, wordpress-theming and wp-nav-walker from the question as they are irrelevant to the bug and perhaps add safari, ios and/or ipad to it.

Grouping/GROUP BY With LINQ in MVC

I am new in MVC. In this page; I list the projects belonging to the "unit name" by loop. And what I want to do: I want to group projects belonging to the same "unit name". Each project has a "unit name" to which it belongs. There can be more than one project belonging to one unit. So I want to group it.
My cshtml code is as follows:
#if (Model.Projects.Any())
{
foreach (var item in Model.Projects.ToList())
{
<div class="ProjectPartialBody" data-id="#item.ID">
<div class="portlet box blue">
<div class="portlet-title">
<div class="caption">
<span><i class="glyphicon glyphicon-asterisk"></i> #item.tbl_Unit.Name</span>
</div>
<div class="tools">
</div>
<div class="actions">
Details
</div>
</div>
<div class="portlet-body">
<span><i class="fa fa-file"></i> #item.Name</span>
<span><i class="fa fa-calendar"> Contract Start and End Dates: #(item.ContractStartDate != null ? item.ContractStartDate.Value.ToString("dd.MM.yyyy") : "-") / #(item.ContractEndDate != null ? item.ContractEndDate.Value.ToString("dd.MM.yyyy") : "-")</i></span>
<div class="well">
<div class="form-group">
<label>Cash Completion Rate: %#item.CashCompletionRate</label>
<div class="progress progress-striped active">
<div class="progress-bar progress-bar-info" role="progressbar" style="width: #(item.CashCompletionRate)%;"></div>
</div>
</div>
</div>
<div class="well">
<div class="form-group">
<label>Physical Completion Rate: %#item.PhysicalCompletionRate</label>
<div class="progress progress-striped active">
<div class="progress-bar progress-bar-info" role="progressbar" style="width: #(item.PhysicalCompletionRate)%;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
}
}
And the view of the page is as follows (my view is in Turkish language but you'll understand what I am talking about):
My Page View
Can you please help me? And if there is any other code block you want to insert, please tell me.
You first need to group by in your for statement:
foreach(var unitGroup in Model.Projects.GroupBy(g => g.tbl_Unit.Name))
{
//...your MVC markup here
}
Now you actualy need to change the markup as you would need to put in another foreach loop that would generate markup for projects.
So something simillar to this.
<div class="ProjectPartialBody" data-id="#item.ID">
<div class="portlet box blue">
<div class="portlet-title">
<div class="caption">
<span><i class="glyphicon glyphicon-asterisk"></i> #item.tbl_Unit.Name</span>
</div>
<div class="tools">
</div>
<div class="actions">
Details
</div>
</div>
#foreach(var project in unitGroup.ToList())
{
<div class="portlet-body">
<span><i class="fa fa-file"></i> #project.Name</span>
<span><i class="fa fa-calendar"> Contract Start and End Dates: #(project.ContractStartDate != null ? project.ContractStartDate.Value.ToString("dd.MM.yyyy") : "-") / #(project.ContractEndDate != null ? project.ContractEndDate.Value.ToString("dd.MM.yyyy") : "-")</i></span>
<div class="well">
<div class="form-group">
<label>Cash Completion Rate: %#project.CashCompletionRate</label>
<div class="progress progress-striped active">
<div class="progress-bar progress-bar-info" role="progressbar" style="width: #(project.CashCompletionRate)%;"></div>
</div>
</div>
</div>
<div class="well">
<div class="form-group">
<label>Physical Completion Rate: %#project.PhysicalCompletionRate</label>
<div class="progress progress-striped active">
<div class="progress-bar progress-bar-info" role="progressbar" style="width: #(project.PhysicalCompletionRate)%;"></div>
</div>
</div>
</div>
</div>
}
</div>
</div>
There should be some errors here as I am not very familliar with your model but this should be the general idea behind it.

create csv from html

I have the code, I need it to get a csv file with the following contents.
src of img.myImg; content of EAN: Z88799010290
I tried, but no luck how merge two foreach:
foreach($html->find('img.myImg') as $e)
echo $e->src . '<br>;';
foreach($html->find('div.EANN') as $ean)
echo $ean. ';<br>';
<div id="wybr_45" alt="-8204" class="listProduct"><div id="d4b">
<div class="fl fotoimage">
<div class="listLink1"> <a href="#" onclick="changeData('popshop','Mainframe','showModuleNew','DeepProductSelect',1234,1234);" >
<img src="http://example/script.php?a=87x112&t=B2B.BSDTrade&i=-441" class="myImg" alt="w"/> </a>
</div>
</div>
<div class="fl descriptionColumn">
<div class="lpTitle2 listName"><b> GATTA: MICHELLE LOVE pończochy samonośne wz.03</b></div>
<div class="lpTitle2"><!-- <a href="#" >brak opisu </a> --></div>
<span class="lpTitle2">Kod:</span><b>-8204</b>
<div class="EANN">000245035190</div><div class="lpTitle2 producer">Producent: <a style="font-size: 12px; color: #555;" href="#">GATTA</a></div>
</div>
<div class="marketIndex">
<div class="priceColumn"> <span class="oldPrice1">
</span></div>
<div class="OrderCpl"><span class="addtoOrderL" onclick="deepProductTable_showForProduct(-8204);" >
<span onclick="deepProductTable_showForProduct(-8204);" class="addtobasket"/> </span></div>
</div></div></div>
Result:
http://example/script.php?a=87x112&t=B2B.BSDTrade&i=-723;000937090290

Resources