How to populate data on nav-tab in partial View in MVC? - asp.net-mvc

I have partial View where I have 2 nav-tab. On Each tab, I want to populate data based on Country.
Currently, I am getting following error:
Insufficient stack to continue executing the program safely. This can
happen from having too many functions on the call stack or function on
the stack using too much stack space.
Controller
public ActionResult Index()
{
ClsHome model = new ClsHome();
return View(model);
}
public PartialViewResult EmployeeBasedCountry(int CountryId)
{
ClsHome clshome=new ClsHome();
clshome.Country = CountryId;
clshome.countries = CountryFilter(CountryId);
return PartialView("~/Views/Home/_pEmp.cshtml", clshome);
}
Index View
#model EmpWebsite.Models.Home.ClsHome
<div class="col-md-5">
#Html.Partial("_pEmp")
</div>
Partial View
#model EmpWebsite.Models.Home.ClsHome
<ul class="nav nav-tabs nav-justified">
<li class="active"><a data-toggle="tab" href="#Tab1">India</a></li>
<li><a data-toggle="tab" href="#Tab2" style="width:auto">USA</a></li>
</ul>
<div class="tab-content">
<div id="Tab1" class="tab-pane fade">
#Html.Action("EmployeeBasedCountry", new { #CountryId = "1" })
<div class="panel">
<table class="table-striped">
<tr class="heading">
<th>
EmpId
</th>
<th>
EmpName
</th>
</tr>
#foreach (var item in Model)
{
<tr>
<td>
#item.EmpId
</td>
<td>
<a>#item.EmpName</a>
</td>
</tr>
}
</table>
</div>
</div>
<div id="Tab2" class="tab-pane fade">
#Html.Action("EmployeeBasedCountry", new { #CountryId = "2" })
<div class="panel">
<table class="table-striped">
<tr class="heading">
<th>
EmpId
</th>
<th>
EmpName
</th>
</tr>
#foreach (var item in Model)
{
<tr>
<td>
#item.EmpId
</td>
<td>
<a>#item.EmpName</a>
</td>
</tr>
}
</table>
</div>
</div>
</div>

Related

I have a problem when I try to render a partial view in may main view

I have the following partial view:
#model IDECOHealthInsurance.Models.Pharmacy
#using (Ajax.BeginForm("pharmacyDetials", "Pharmacy", new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "pDetail", InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace, LoadingElementId = "Loading", OnBegin = "" }))
{
<h4>تفاصيل الصيدلية</h4>
<div id="pDetail" class="MainGridContainer pb-5">
#if (Model.dtItemsDetails != null)
{
<table dir="rtl" id="Paitents" class="MainGrid">
<thead>
<tr style="text-size-adjust:auto">
<th>
رقم الموظف
</th>
<th>
التاريخ
</th>
<th>
الوقت
</th>
<th>
المستفيدون
</th>
<th>
ملاحظات
</th>
<th>
الباركورد
</th>
<th>
أسم العينة
</th>
<th>
الكمية
</th>
<th>
السعر
</th>
</tr>
</thead>
<tbody>
#foreach (System.Data.DataRow row in Model.dtItemsDetails.Rows)
{
<tr style="width:100%">
<td>
#row["EMPLOYEE_NUMBER"]
</td>
<td>
#row["ENTRY_DATE"]
</td>
<td>
#row["ENTRY_TIME"]
</td>
<td>
#row["BENEFICIARIES"]
</td>
<td>
#row["NOTE"]
</td>
<td>
#row["ITEM_CODE"]
</td>
<td>
#row["ITEM_NAME"]
</td>
<td>
#row["QTY"]
</td>
<td>
#row["PRICE"]
</td>
</tr>
}
</tbody>
</table>
}
</div>
}
And the follwing controller:
[HttpGet]
public ActionResult pharmacyDetials(Pharmacy model)
{
var masterID = Convert.ToInt32(Session["login"]);
if (masterID == 0)
{
return RedirectToAction("Login");
}
else
{
Models.Pharmacy objPharamcyMode = new Pharmacy();
IDECOServiceReference.IdecoAPIServiceClient idecoAPI = new IDECOServiceReference.IdecoAPIServiceClient();
DataTable dataTable = idecoAPI.GETPHARMACYEMPLOYEEMASTER("", 1);
model.dtItemsDetails = dataTable;
return PartialView("_PharmacyDetails", model);
}
}
And the following main view:
#model IDECOHealthInsurance.Models.Pharmacy
#{
ViewBag.Title = "PharmacyApplication";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<table style="height:680px; width:1280px; border:hidden">
<tr>
<td>
<div id="pDetail">
#Html.Partial("_PharmacyDetails", Model)
</div>
</td>
<td>
#using (Ajax.BeginForm("PharmacyApplication", "Pharmacy", new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "updatePnl", InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace, LoadingElementId = "Loading", OnBegin = "" }))
{
<div class="form-horizontal">
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" id="panel" value="أضافة" class="btn btn-default" />
</div>
<input class="btn btn-default" type="button" value="خروج" onclick="#("window.location.href='" + #Url.Action("LogOut", "Pharmacy") + "'");" />
</div>
</div>
}
</td>
</tr>
</table>
<div id="updatePnl">
#Html.Partial("_PartialPharmacyDetails", Model)
</div>
<br />
<br />
<br />
<div id="pnlItemsDetails">
#Html.Partial("_PartialItemsDetails", Model)
</div>
When I try to render _PharmacyDetails in my main view it won't return any records. What is the problem? and how I can fix it? Please provide me with an explanation of how this problem occurs. What did I do wrong?
Instead of using Partial method to render the partial view I used Action method:
<tr>
<td>
<div id="pDetail" style="background-color:aliceblue" method="Get">
#Html.Action("pharmacyDetials", Model)
</div>
</td>
<td>

Merge different data with same Id in 'TR' tag in MVC view

This is my current structure in the view :
Now as per the above image, the Movie 'Avengers' is having same Movieid in my table, but different celebs like Scarlett,Robert, etc. But the records for 'Russo' & 'Scarlett' are placed in different Tr tag. How can i be able to move these two records in the same Tr below 'Robert Jr.'.
I have tried this, but this gives me the output in the image above :
<table class="table table-bordered" id="topicList">
<thead>
<tr><th data-priority="1"><span>Movies</span></th>
<th data-priority="3"><span>Roles</span></th></tr>
</thead>
<tbody>
#{ int movieid = 0; }
#foreach (var item in Model)
{
<tr>
<td class="topicTd">
#if (movieid != item.MovieId)
{
<div class="table_home">
<span>#item.MovieName</span>
</div>
}
#{ movieid = item.MovieId; }
</td>
<td>
<div id="roles">
<div class="img_div">
<div class="rolelistTooltip">
<a href="javascript:void(0);" class="hover right_div" data-trigger="focus" id="229759" role="button">
<img src="~/Content/0829.jpg" class="imgSquare img-responsive img-circle" alt="#item.CelebName">
</a>
</div>
</div>
<div class="content_img">
<h3><strong class="groupID11">#item.CelebName</strong></h3>
<p>
#item.RoleName
</p>
</div>
</div>
</td>
</tr>
}
</tbody>
This is the model :
Int MovieId, string MovieName, int celebId, string CelebName, int roleId, string RoleName

keep the checkbox checked browsing through the paging (Using PagedList asp.net mvc)

I have a list of orders in a gridview with customer html which has paging using PagedList asp.net mvc. I have a checkbox for each order in the list. When I use "Check all" to check all orders it should keep the checkbox checked when I go to page 2-3-4. But I lose the checked status when I move to next page. Can anyone help please?
JavaScript code :
$(document).ready(
function () {
$('#selectAll').click(
function () {
$('#TabOrdre td input:checkbox').prop('checked', $(this).is(':checked'));
if ($(this).is(':checked')) {
$('#TabOrdre td input:checkbox').each(function () {
if ($.inArray($(this).val(), list) === -1)
list.push($(this).val());
});
getAll = true;
}
else {
list = [];
getAll = false;
}
}
);
View code :
<section class="panel panel-default">
<header class="panel-heading m-b-none">Liste des ordres</header>
<div class="row wrapper">
<div class="col-md-12 space20">
<div class="doc-buttons">
<a class="btn btn-s-md btn-warning ajout-container"> <i class="fa fa-plus"></i> Ajouter un ordre </a>
</div>
</div>
</div>
<div class="table-responsive">
<table class="table table-striped b-t b-light">
<thead>
<tr>
<th width="20">
<input type="checkbox" id="selectAll" value="-1">
</th>
<th style="white-space:nowrap">
EDA
</th>
<th style="white-space:nowrap">
<span class="th-sort">
Immediat
</span>
</th>
<th style="white-space:nowrap">
JNA
</th>
<th style="white-space:nowrap">
Date
</th>
<th style="white-space:nowrap">
Heure début
</th>
<th style="white-space:nowrap">
Heure fin
</th>
<th style="white-space:nowrap">
Puissance
</th>
<th style="white-space:nowrap">
RP
</th>
<th style="white-space:nowrap">
RS
</th>
<th style="white-space:nowrap">
Caractérisation
</th>
<th style="white-space:nowrap">
Commentaire
</th>
<th style="white-space:nowrap">
Source
</th>
<th style="white-space:nowrap">
Date de création
</th>
<th style="white-space:nowrap">
Refus
</th>
<th style="white-space:nowrap" class="th-sortable" data-toggle="class">
</th>
</tr>
</thead>
<tbody>
#if (Model.Count > 0)
{
foreach (var item in Model)
{
#Html.HiddenFor(model => item.ORD_ID)
<tr>
<td>
<input type="checkbox" value="#item.ORD_ID" id="chk_#item.ORD_ID" />
</td>
<td>
#Html.DisplayFor(model => item.EDA_NOM)
</td>
<td>
#(Convert.ToBoolean(item.EDA_IMMEDIAT) ? "Oui" : "Non")
</td>
<td>
#(Convert.ToBoolean(item.EDA_JNA) ? "Oui" : "Non")
</td>
<td>
#if (item.EDA_ORDRE_DATE_DEBUT != null)
{#Html.DisplayFor(model => item.EDA_ORDRE_DATE_DEBUT, "ShortDateTime")}
</td>
<td style="white-space:nowrap">
#if (item.EDA_ORDRE_DATE_DEBUT != null)
{#Html.DisplayFor(model => item.EDA_ORDRE_DATE_DEBUT, "ShortTimeString")}
</td>
<td>
#if (item.EDA_ORDRE_DATE_FIN != null)
{ #Html.DisplayFor(model => item.EDA_ORDRE_DATE_FIN, "ShortTimeString")}
</td>
<td>
#Html.DisplayFor(model => item.EDA_PUISSANCE)
</td>
<td>
#Html.DisplayFor(model => item.EDA_PUISSANCE_RP)
</td>
<td>
#Html.DisplayFor(model => item.EDA_PUISSANCE_RS)
</td>
<td>
#Html.DisplayFor(model => item.Eda_Caracterisation)
</td>
<td>
#Html.DisplayFor(model => item.COMMENTAIRE)
</td>
<td>
#Html.DisplayFor(model => item.SOURCE_NOM)
</td>
<td>
#if (item.EDA_DATE_RECUPEREE != null)
{ #Html.DisplayFor(model => item.EDA_DATE_RECUPEREE, "ShortDateTime")}
</td>
<td>
#Html.DisplayFor(model => item.VAL_REFUS)
</td>
<td >
#if (item.MODIFIABLE == 0)
{
<a class="btn btn-warning editor-container" data-id="#item.ORD_ID" data-toggle="modal"
><i class="fa fa-edit"></i></a>
}
</td>
</tr>
}
}
else
{
<tr>
<td class="text-center " colspan="16">
#VideResult
</td>
</tr>
}
</tbody>
</table>
</div>
<footer class="panel-footer">
<div class="row">
<div class="col-sm-4 ">
<button type="submit" class="btn btn-s-md btn-warning" id="Accepter">Accepter</button>
<button class="btn btn-s-md btn-default" id="Refuser">Refuser</button>
</div>
<div class="col-sm-4 text-center">
</div>
<div class="col-sm-4 text-right text-center-xs">
#Html.PagedListPager(Model, Page_No => Url.Action("Liste",
new
{
eda = ViewBag.eda,
Source = ViewBag.Source
,
datedeb = ViewBag.datedeb
,
datefin = ViewBag.datefin
,
refus = ViewBag.refus
,
page = Page_No
}),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(PagedListRenderOptions.ClassicPlusFirstAndLast
, new AjaxOptions()
{
HttpMethod = "GET",
UpdateTargetId = "TabOrdre",
LoadingElementId = "loader"
}))
</div>
</div>
</footer>
</section>

MVC Table filtered multiple times on same View

I'm trying to show different results of the same table (group column values), each time I click on a tab, in the same view.
To clarify please check:
The view code:
#model IEnumerable<RapidScan_v2.Models.lu_performance_reason>
#{
ViewBag.Title = "Index";
}
<h2>Playbook</h2>
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"> Consumables</li>
<li role="presentation"> DocuCare Labour</li>
<li role="presentation"> Parts</li>
<li role="presentation"> Print Production Labour</li>
<li role="presentation"> Revenue</li>
<li role="presentation"> Technical Service</li>
<li role="presentation"> Depreciation</li>
<li role="presentation"> Other Costs</li>
</ul>
#section LeftMenu{
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="Consumables">
#using (Html.BeginForm())
{
<p>
Consumables: #Html.Hidden("search1","Consumables")
<input type="submit" value="Search" />
</p>
}
<table class="table">
<tr>
<th>
Perf Reason
</th>
<th>
Action
</th>
<th>
Action Description
</th>
<th>
Info EU
</th>
<th>
Info US
</th>
<th>
Helper Team
</th>
<th>
Target
</th>
<th>
Group
</th>
<th>
Cost Reason
</th>
<th></th>
</tr>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.dsc_performance_reason)
</td>
<td>
#Html.DisplayFor(modelItem => item.dsc_investigation_actions)
</td>
<td>
#Html.DisplayFor(modelItem => item.dsc_actions)
</td>
<td>
#Html.DisplayFor(modelItem => item.dsc_additional_info_europe)
</td>
<td>
#Html.DisplayFor(modelItem => item.dsc_additional_info_usa)
</td>
<td>
#Html.DisplayFor(modelItem => item.lu_action_helper.dsc_action_helper)
</td>
<td>
#Html.DisplayFor(modelItem => item.lu_action_target.dsc_action_target)
</td>
<td>
#Html.DisplayFor(modelItem => item.lu_cost_bucket.dsc_cost_bucket)
</td>
<td>
#Html.DisplayFor(modelItem => item.lu_cost_reason.dsc_cost_reason)
</td>
<td>
#Html.ActionLink("Add to Contract", "Create", "fact_contract_actions_mn", new { id = item.cod_performance_reason }, null)
</td>
</tr>
}
</table>
</div>
<div role="tabpanel" class="tab-pane" id="DocuCareLabour">
<p>DocuCare Labour</p>
</div>
<div role="tabpanel" class="tab-pane" id="Parts">
<p>Parts</p>
</div>
<div role="tabpanel" class="tab-pane" id="PrintProductionLabour">
<p>Print Production Labour</p>
</div>
<div role="tabpanel" class="tab-pane" id="Revenue">
<p>Revenue</p>
</div>
<div role="tabpanel" class="tab-pane" id="TechnicalService">
<p>Technical Service</p>
</div>
<div role="tabpanel" class="tab-pane" id="Depreciation">
<p>Depreciation</p>
</div>
<div role="tabpanel" class="tab-pane" id="OtherCosts">
<p>Other Costs</p>
</div>
</div>
}
I'll replicate the table through all "tabs" with fewer columns after this is solved. I've added a search function on the controller but I beleive there's a better way since this only returns what I want after an input.
Here's the controller code:
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using RapidScan_v2.Models;
namespace RapidScan_v2.Controllers
{
public class lu_performance_reasonController : Controller
{
private RapidScanEntities2 db = new RapidScanEntities2();
// GET: lu_performance_reason
public ActionResult Index(string search1)
{
var lu_performance_reason = from lpr in db.lu_performance_reason.Include(l => l.lu_action_helper).Include(l => l.lu_action_target).Include(l => l.lu_cost_bucket).Include(l => l.lu_cost_reason)
select lpr;
if (!string.IsNullOrEmpty(search1))
{
lu_performance_reason = lu_performance_reason.Where(lpr => lpr.lu_cost_bucket.dsc_cost_bucket.Contains(search1));
}
return View(lu_performance_reason.ToList());
}
I believe that Filtering is the answer but I'm stuck at the moment.
As I've said, filtering was the answer.
Just followed the answer in question: MVC 3 model foreach filter

ViewBag is null on the second page of PagedList in mvc application

I m stuck on this for a while now and will appreciate any help.
The value of ViewBag.SearchTerm is null when I click on the 2 item in the paged list. My List page is present in a partial view (_CentraladdrcdoQuery) as below
#using SFRS.GazMatching.Web.DAL
#model IPagedList<CentraladdrcdoQuery>
#using PagedList;
#using PagedList.Mvc;
<div id="results" class="col-md-10">
<div class="row">
<div class="col-md-4">
<table class="table pull-left table-condensed">
<tr>
<td>
#Html.DisplayNameFor(model => model.First().RecordId)
</td>
</tr>
</table>
</div>
<div class="col-md-4">
<table class="table pull-left table-condensed">
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.RecordId)
</td>
</tr>
}
</table>
</div>
<br />
</div>
<div class="row">
<div class="col-md-4 clearfix">
#Html.PagedListPager(Model, page => Url.Action("Search", new { page, ViewBag.SearchTerm }), new PagedListRenderOptions
{
LinkToFirstPageFormat = "<<",
LinkToPreviousPageFormat = "prev",
LinkToNextPageFormat = "next",
LinkToLastPageFormat = ">>",
})
</div>
</div>
The main search view is
#model IPagedList<CentraladdrcdoQuery>
#{
SearchFormViewModel searchFormViewModel = new SearchFormViewModel();
}
#Html.Partial("_SearchForm",searchFormViewModel)
<h2>Search Results</h2>
#Html.Partial("_CentraladdrcdoQuery", Model)
and the Search Controller action is
public ActionResult Search(string searchTerm, int? page)
{
var centraladdrcdoQuerylst= GetCentraladdrcdoQueryData(searchTerm,page);
ViewBag.SourceList = GetSourceList();
ViewBag.SearhTerm = searchTerm;
return View(centraladdrcdoQuerylst);
}

Resources