Create dynamic div Razor MVC - css

I want to create a dynamic div.
I have a list of products which maximum 3 can be in one row "col-xs-4" but if they are 4 products I want 3 with "col-xs-4" and the 4th being with "col-xs-12" to fill the entire row. If I have 5 products I want 3 with "col-xs-4" and the other 2 with "col-xs-6".
I was thinking about depending on the count of the items I set the class
<div class="flippersContainer">
<div class="container">
<div class="col-xs-12">
#{
var children = Model.Content.Children.ToList();
if (children.Any())
{
foreach (var item in children.OfType<RedButtonItem1>())
{
string imagePath = string.Empty;
if (!string.IsNullOrEmpty(item.Image))
{
var itemImage = Umbraco.TypedMedia(item.Image);
imagePath = itemImage.GetCropUrl(80, 160);
}
{
string colCSS = string.Empty;
var productNumber = children.OfType<RedButtonItem1>().Count();
}
<div class="col-xs-4">
<div class="front-two">
<div class="flipperAllFront">
<div class="big-button">
<img class="img-responsive" src="https://www.atlantico.ao/SiteCollectionImages/PARTICULARES/ContaGlobal/Atlantico-Conta-Global-375X178.jpg">
<div class="productTitle">
<span>#item.Title</span>
</div>
<div class="productText">
<span>#item.Description</span>
</div>
#{
if (item.CallToAction != null && item.CallToAction.HasValues)
{
var linkUrl = (item.CallToAction.First.Value<bool>("isInternal")) ? (item.CallToAction.First.Value<int?>("internal").HasValue ? Umbraco.NiceUrl(item.CallToAction.First.Value<int>("internal")) : string.Empty) : item.CallToAction.First.Value<string>("link");
var linkTarget = item.CallToAction.First.Value<bool>("newWindow") ? "_blank" : null;
#:<a role="button" href="#linkUrl" target="#linkTarget">
}
else
{
#:<a class="link-big-button" role="button" data-parent="#accordion" href="##item.Id">
}
#:</a>
}
</div>
</div>
</div>
</div>
}
}
}
</div>
</div>
Thanks in Advance

<div class="col-xs-#(childrenCount==3?"4":childrenCount==4?"3":childrenCount==5?"3":"6")">
<div class="flippersContainer">
<div class="container">
<div class="col-xs-12">
#{
var children = Model.Content.Children.ToList();
int childrenCount = children.OfType<RedButtonItem1>().Count;
if (children.Any())
{
foreach (var item in children.OfType<RedButtonItem1>())
{
string imagePath = string.Empty;
if (!string.IsNullOrEmpty(item.Image))
{
var itemImage = Umbraco.TypedMedia(item.Image);
imagePath = itemImage.GetCropUrl(80, 160);
}
{
string colCSS = string.Empty;
var productNumber = children.OfType<RedButtonItem1>().Count();
}
<div class="col-xs-#(childrenCount==3?"4":childrenCount==4?"3":childrenCount==5?"3":"6")">
<div class="front-two">
<div class="flipperAllFront">
<div class="big-button">
<img class="img-responsive" src="https://www.atlantico.ao/SiteCollectionImages/PARTICULARES/ContaGlobal/Atlantico-Conta-Global-375X178.jpg">
<div class="productTitle">
<span>#item.Title</span>
</div>
<div class="productText">
<span>#item.Description</span>
</div>
#{
if (item.CallToAction != null && item.CallToAction.HasValues)
{
var linkUrl = (item.CallToAction.First.Value<bool>("isInternal")) ? (item.CallToAction.First.Value<int?>("internal").HasValue ? Umbraco.NiceUrl(item.CallToAction.First.Value<int>("internal")) : string.Empty) : item.CallToAction.First.Value<string>("link");
var linkTarget = item.CallToAction.First.Value<bool>("newWindow") ? "_blank" : null;
#:<a role="button" href="#linkUrl" target="#linkTarget">
}
else
{
#:<a class="link-big-button" role="button" data-parent="#accordion" href="##item.Id">
}
#:
</a>
}
</div>
</div>
</div>
</div>
}
}
}
</div>
</div>

Related

Check if IEnumerable list in View Model is null in View

I just wanted to check if it's possible to check if an IEnumerable list is null in the view when passed from the controller via the view model. Or should I only create conditions in the controller?
My code below does not show the else condition.
Apologies if this is painfully obvious to everyone but I'm still only learning and thanks in advance for any pointers in the right direction.
My controller:
[Area("User")]
[Authorize]
public class TrayController : Controller
{
private readonly IUnitOfWork _unitOfWork;
public OfferTrayVM OfferTrayVM { get; set; }
public TrayController(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public IActionResult Index()
{
var claimsIdentity = (ClaimsIdentity)User.Identity;
var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
OfferTrayVM = new OfferTrayVM()
{
ListOfferTray = _unitOfWork.OfferTray.GetAll(u => u.ApplicationUserId == claim.Value,
includeProperties: "Trade")
};
return View(OfferTrayVM);
}
public IActionResult Delete(int trayId)
{
var tray = _unitOfWork.OfferTray.GetFirstOrDefault(u => u.Id == trayId);
_unitOfWork.OfferTray.Remove(tray);
_unitOfWork.Save();
return RedirectToAction("Index", "Home", new { area = "User" });
}
}
My view model:
public class OfferTrayVM
{
public IEnumerable<OfferTray> ListOfferTray { get; set; }
}
My view:
#model QPQ.Models.ViewModels.OfferTrayVM
<form method="post">
<br />
<div class="container">
<div class="card">
<div class="card-header bg-dark text-light ml-0">
<div class="row">
<div class="col-6 pt-2">
Summary Confirmation
</div>
<div class="col-6 text-end">
</div>
</div>
</div>
#if(Model.ListOfferTray != null)
{
<div class="card-body">
#foreach (var item in Model.ListOfferTray)
{
<div class="row">
<div class="col-12 col-lg-4 pt-md-3">
<h5><strong>#item.Trade.CompanyName - Have offered to trade: </strong></h5>
<p><small>#item.Trade.Description</small></p>
<hr>
<h5><strong>#item.Trade.CompanyName - Have requested in Return: </strong></h5>
<p><small>item.Trade.InReturnFor</small></p>
</div>
<div class="col-12 col-lg-4 pt-md-3">
<h5><strong>You are Offering in return:</strong></h5>
<p><small>#item.OfferInReturn</small></p>
</div>
<div class="col-12 col-lg-4 text-center row">
<div class="col-sm-4 text-right pt-2">
<a asp-action="Delete" asp-route-trayId="#item.Id" class="btn btn-danger">
<i class="bi bi-trash-fill">Delete</i>
</a>
</div>
</div>
</div>
<hr />
}
</div>
}
else
{
<div class="card-body">
<h3>You do not have any existing offers. Please click<a asp-action="index" asp-area="Home">here</a>to continue.</h3>
</div>
}
<div class="card-footer">
<div class="card-footer row">
<div class="col-sm-12 col-lg-4 col-md-6 offset-lg-8 offset-md-6 ">
<a class="btn btn-success form-control">Summary</a>
</div>
</div>
</div>
</div>
</div>
</form>

Why do my styles stop working in the DETAIL mode, UPDATE and if they do it in SAVE (same ASP.NET view)?

Good morning everyone,
I have an inconvenient in one of my ASP .NET views that is driving me crazy. I have a complete maintenance for a module, consisting of searches, detail, update and registration. For this detail, update and record use the same view only that, depending on the case, the text entries and buttons are drawn in the view with SWITCH's. Until a few days ago everything worked fine, however, I added some extra text entries and other minor changes. Today, I have finished developing the module; I have tried the save view and everything is fine, but when I try the same view in detail mode and update, all my styles disappear. I even see, my Layout without formatting. I read the console and it tells me that it does not find the files and it seems super strange since it is the same view as in the save mode. I would greatly appreciate your help, thanks in advance, anyway.
optimum
enter image description here
not optimal
enter image description here
#model CaucionesWeb.Models.CGRegistroViewModel
#{
ViewBag.Title = "Contragarantías";
string VistaSeleccionada = ViewBag.VistaSeleccionada;
string Action = VistaSeleccionada.Equals("Obtener") ? "Aprobar" : VistaSeleccionada;
string descriptionStatusWarr = string.Empty;
string descriptionTypeWarr = string.Empty;
string descriptionCurrency = string.Empty;
string descriptionStatusSit = string.Empty;
string disabledClass = string.Empty;
}
#using (Html.BeginForm(Action, "CGRegistro", FormMethod.Post, new { id = "formulario" }))
{
#Html.AntiForgeryToken()
<div class="container-fluid">
<div class="title clear">
<h1 class="fl-left fz-22 push-0">Contragarantías: Registro</h1>
<div class=" btn-group push-top-0">
<div class="row">
<div class="pull-right">
#switch (VistaSeleccionada)
{
case "Obtener":
switch (Convert.ToInt32(Session["SchemeId"]))
{
case 1:
Nuevo
Editar
break;
case 2:
Nuevo
Editar
break;
case 4:
switch (Model.StatusWarr)
{
case 2:
<button type="button" class="btn btn-primary mr-1 mt-1 disabled">Aprobar</button>
break;
case 3: //
<button type="button" class="btn btn-primary mr-1 mt-1 disabled">Aprobar</button>
break;
default:
if (Convert.ToDateTime(Model.EffectDate) >= Model.d_hoy) //SI LA CG A APROBAR ES O HA PASADO LA FECHA DE EFECTO
{
<button type="button" class="btn btn-primary mr-1 mt-1 disabled">Aprobar</button>
}
else
{
<button type="submit" class="btn btn-primary mr-1 mt-1">Aprobar</button>
}
break;
}
break;
case 5:
<!--NADA-->
break;
}
break;
case "Actualizar":
<button id="btnAceptar" type="submit" class="btn btn-primary mr-1 mt-1">Aceptar</button>
break;
case "Guardar":
<button id="btnAceptar" type="submit" class="btn btn-primary mr-1 mt-1">Aceptar</button>
break;
}
Cancelar
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6 mb-mt pr-4 pt-1 pl-2 ">
<h4>Datos Generales</h4>
<div class="line-x"></div>
</div>
<div class="push-top-0">
<div class="row">
<div class="col-md-12 mb-mt">
<div class="col-md-3">
<div class="pt-1 pr-4 pl-2">
<div class="ui-input ui-field readonly">
#if (VistaSeleccionada.Equals("Guardar"))
{
<input class="ui-field-input " readonly="" />
}
else
{
#Html.TextBoxFor(m => m.WarrantiesId, new { #class = "ui-field-input", #readonly = "true" })
}
#Html.LabelFor(m => m.WarrantiesId, new { #class = "ui-field-label" })
<div class="ui-field-hr">
<hr class="ui-field-hr-highlight">
</div>
</div>
</div>
</div>
<div class="col-md-3">
<div class="pt-1 pr-4 pl-2">
#Html.HiddenFor(m => m.StatusWarr)
#foreach (var item in Model.StatusWarrList)
{
if (item.value == Model.StatusWarr)
{
descriptionStatusWarr = item.name;
}
}
#switch (VistaSeleccionada)
{
case "Obtener":
<div class="ui-input ui-field">
#Html.TextBox("x", descriptionStatusWarr, new { #class = "ui-field-input", #readonly = "true" })
#Html.LabelFor(m => m.StatusWarr, new { #class = "ui-field-label" })
<div class="ui-field-hr">
<hr class="ui-field-hr-highlight">
</div>
</div>
break;
case "Actualizar":
<div class="ui-input ui-field">
#Html.TextBox("x", descriptionStatusWarr, new { #class = "ui-field-input", #readonly = "true" })
#Html.LabelFor(m => m.StatusWarr, new { #class = "ui-field-label" })
<div class="ui-field-hr">
<hr class="ui-field-hr-highlight">
</div>
</div>
break;
case "Guardar":
<div class="ui-input ui-select ui-dropdown asiggned active disabled" id="cboStatusWarr">
<span class="icon ico-arrow-bottom"></span><span for="input-8" class="ui-select-label">#Html.DisplayNameFor(m => m.StatusWarr)</span>
<input class="ui-select-filter">
<div class="ui-select-btn"><span class="ui-select-value">Pte. de Aprobación</span></div>
<div class="ui-select-hr">
<hr class="ui-select-hr-highlight">
</div>
<div class="ui-dropdown-content">
<ul class="ui-dropdown-list">
#foreach (var item in Model.StatusWarrList)
{
<li class="ui-dropdown-list-item" data-value="#item.value" data-label="#item.name"><span>#item.name</span></li>
}
</ul>
</div>
</div>
break;
}
</div>
</div>
</div>
<div class="col-md-12 mb-mt">
...
</div>
<div class="col-md-12 mb-mt">
<div class="row">
<div class="col-md-3">
<div class="pt-1 pr-4 pl-2">
#foreach (var item in Model.TypeWarrList)
{
if (item.value == Model.TypeWarr)
{
descriptionTypeWarr = item.name;
}
}
#switch (VistaSeleccionada)
{
case "Obtener":
<div class="ui-input ui-select ui-dropdown asiggned active disabled" id="cboTypeWarr">
<span class="icon ico-arrow-bottom"></span><span for="input-8" class="ui-select-label">#Html.DisplayNameFor(m => m.TypeWarr)</span>
<input class="ui-select-filter">
<div class="ui-select-btn"><span class="ui-select-value">#descriptionTypeWarr</span></div>
<div class="ui-select-hr">
<hr class="ui-select-hr-highlight">
#Html.TextBoxFor(m => m.TypeWarr, new { #class = "input-invisible" })
</div>
<div class="ui-dropdown-content">
<ul class="ui-dropdown-list"></ul>
</div>
</div>
break;
case "Actualizar":
switch (Model.StatusWarr)
{
case 2:
disabledClass = "disabled";
break;
default:
disabledClass = string.Empty;
break;
}
<div class="ui-input ui-select ui-dropdown asiggned active #disabledClass" id="cboTypeWarr">
<span class="icon ico-arrow-bottom"></span><span for="input-8" class="ui-select-label">#Html.DisplayNameFor(m => m.TypeWarr)</span>
<input class="ui-select-filter">
<div class="ui-select-btn"><span class="ui-select-value">#descriptionTypeWarr</span></div>
<div class="ui-select-hr">
<hr class="ui-select-hr-highlight">
#Html.TextBoxFor(m => m.TypeWarr, new { #class = "input-invisible", #required = "true" })
</div>
<div class="ui-dropdown-content">
<ul class="ui-dropdown-list">
#if (string.IsNullOrEmpty(disabledClass))
{
foreach (var item in Model.TypeWarrList)
{
<li class="ui-dropdown-list-item" data-value="#item.value" data-label="#item.name"><span>#item.name</span></li>
}
}
</ul>
</div>
</div>
break;
case "Guardar":
<div class="ui-input ui-select ui-dropdown asiggned" id="cboTypeWarr">
<span class="icon ico-arrow-bottom"></span><span for="input-8" class="ui-select-label">#Html.DisplayNameFor(m => m.TypeWarr)</span>
<input class="ui-select-filter">
<div class="ui-select-btn"><span class="ui-select-value"></span></div>
<div class="ui-select-hr">
<hr class="ui-select-hr-highlight">
#Html.TextBoxFor(m => m.TypeWarr, new { #class = "input-invisible", #required = "true", #Value = "" })
</div>
<div class="ui-dropdown-content">
<ul class="ui-dropdown-list">
#foreach (var item in Model.TypeWarrList)
{
<li class="ui-dropdown-list-item" data-value="#item.value" data-label="#item.name"><span>#item.name</span></li>
}
</ul>
</div>
</div>
break;
}
</div>
</div>
...
</div>
</div>
...
...
<div class="col-md-12 mb-mt">
<div class="row">
<div class="col-md-3">
<div class="pt-2 pr-4 pl-2">
#switch (VistaSeleccionada)
{
case "Obtener":
<div class="ui-input ui-field">
#Html.TextBoxFor(m => m.AvalName, new { #class = "ui-field-input", #readonly = "true" })
#Html.LabelFor(m => m.AvalName, new { #class = "ui-field-label" })
<div class="ui-field-hr">
<hr class="ui-field-hr-highlight">
</div>
</div>
break;
case "Actualizar":
switch (Model.StatusWarr)
{
case 2: //APROBADA
<div class="ui-input ui-field">
#Html.TextBoxFor(m => m.AvalName, new { #class = "ui-field-input", #readonly = "true" })
#Html.LabelFor(m => m.AvalName, new { #class = "ui-field-label" })
<div class="ui-field-hr">
<hr class="ui-field-hr-highlight">
</div>
</div>
break;
default:
<div class="ui-input ui-field">
#Html.TextBoxFor(m => m.AvalName, new { #class = "ui-field-input", #required = "true" })
#Html.LabelFor(m => m.AvalName, new { #class = "ui-field-label" })
<div class="ui-field-hr">
<hr class="ui-field-hr-highlight">
</div>
</div>
break;
}
break;
case "Guardar":
<div class="ui-input ui-field">
#Html.TextBoxFor(m => m.AvalName, new { #class = "ui-field-input", #required = "true" })
#Html.LabelFor(m => m.AvalName, new { #class = "ui-field-label" })
<div class="ui-field-hr">
<hr class="ui-field-hr-highlight">
</div>
</div>
break;
}
</div>
</div>
<div class="col-md-3">
<div class="pt-2 pr-4 pl-2">
#foreach (var item in Model.StatusSitList)
{
if (item.value == Model.StatusSit)
{
descriptionStatusSit = item.name;
}
}
#switch (VistaSeleccionada)
{
case "Obtener":
<div class="ui-input ui-select ui-dropdown assigned active disabled" id="cboStatusSit">
<span class="icon ico-arrow-bottom"></span><span for="input-8" class="ui-select-label">#Html.DisplayNameFor(m => m.StatusSit)</span>
<input class="ui-select-filter">
<div class="ui-select-btn"><span class="ui-select-value">#descriptionStatusSit</span></div>
<div class="ui-select-hr">
<hr class="ui-select-hr-highlight">
#Html.TextBoxFor(m => m.StatusSit, new { #class = "input-invisible" })
</div>
<div class="ui-dropdown-content">
<ul class="ui-dropdown-list">
#foreach (var item in Model.StatusSitList)
{
<li class="ui-dropdown-list-item" data-value="#item.value" data-label="#item.name"><span>#item.name</span></li>
}
</ul>
</div>
</div>
break;
case "Actualizar":
<div class="ui-input ui-select ui-dropdown assigned active" id="cboStatusSit">
<span class="icon ico-arrow-bottom"></span><span for="input-8" class="ui-select-label">#Html.DisplayNameFor(m => m.StatusSit)</span>
<input class="ui-select-filter">
<div class="ui-select-btn"><span class="ui-select-value">#descriptionStatusSit</span></div>
<div class="ui-select-hr">
<hr class="ui-select-hr-highlight">
#Html.TextBoxFor(m => m.StatusSit, new { #class = "input-invisible", #required = "true" })
</div>
<div class="ui-dropdown-content">
<ul class="ui-dropdown-list">
#foreach (var item in Model.StatusSitList)
{
<li class="ui-dropdown-list-item" data-value="#item.value" data-label="#item.name"><span>#item.name</span></li>
}
</ul>
</div>
</div>
break;
case "Guardar":
<div class="ui-input ui-select ui-dropdown" id="cboStatusSit">
<span class="icon ico-arrow-bottom"></span><span for="input-8" class="ui-select-label">#Html.DisplayNameFor(m => m.StatusSit)</span>
<input class="ui-select-filter">
<div class="ui-select-btn"><span class="ui-select-value"></span></div>
<div class="ui-select-hr">
<hr class="ui-select-hr-highlight">
#Html.TextBoxFor(m => m.StatusSit, new { #class = "input-invisible", #required = "true", #Value = "" })
</div>
<div class="ui-dropdown-content">
<ul class="ui-dropdown-list">
#foreach (var item in Model.StatusSitList)
{
<li class="ui-dropdown-list-item" data-value="#item.value" data-label="#item.name"><span>#item.name</span></li>
}
</ul>
</div>
</div>
break;
}
</div>
</div>
</div>
</div>
<div class="col-md-6 mb-mt pr-4 pt-1 pl-2 ">
<h4>Información Adicional</h4>
<div class="line-x"></div>
#switch (VistaSeleccionada)
{
case "Obtener":
<div class="ui-input ui-field ui-field-textarea focus-textarea">
#Html.TextAreaFor(m => m.Coments, new { #class = "ui-field-input", #readonly = "true" })
#Html.LabelFor(m => m.Coments)
<div class="ui-field-hr">
<hr class="ui-field-hr-highlight">
</div>
</div>
break;
case "Actualizar":
switch (Model.StatusWarr)
{
case 2:
<div class="ui-input ui-field ui-field-textarea focus-textarea">
#Html.TextAreaFor(m => m.Coments, new { #class = "ui-field-input", #readonly = "true" })
#Html.LabelFor(m => m.Coments)
<div class="ui-field-hr">
<hr class="ui-field-hr-highlight">
</div>
</div>
break;
default:
<div class="ui-input ui-field ui-field-textarea focus-textarea">
#Html.TextAreaFor(m => m.Coments, new { #class = "ui-field-input" })
#Html.LabelFor(m => m.Coments)
<div class="ui-field-hr">
<hr class="ui-field-hr-highlight">
</div>
</div>
break;
}
break;
case "Guardar":
<div class="ui-input ui-field ui-field-textarea">
#Html.TextAreaFor(m => m.Coments, new { #class = "ui-field-input" })
#Html.LabelFor(m => m.Coments)
<div class="ui-field-hr">
<hr class="ui-field-hr-highlight">
</div>
</div>
break;
}
</div>
</div>
</div>
</div>
}
#section Scripts {
<script type="text/javascript">
...
</script>
}

Accordion doesn't automatically count

My accordion doesn't automatically count up, the number stays at 1 for some reason. I am using a CMS called Umbraco on version 7.7.2.
Here's my code:
#if(#Model.Content.GetPropertyValue("titleAccordeon") != "")
{
<section class="block block__accordion">
<div class="container">
<div class="row">
<div class="block__heading col-md-12">
<h3>#Model.Content.GetPropertyValue("titleAccordeon")</h3>
<p>#Model.Content.GetPropertyValue("introAccordeon")</p>
</div>
#if(Model.Content.Accordion != null && Model.Content.Accordion.Any())
{
foreach (var item in Model.Content.Accordion)
{
var guid = Guid.NewGuid();
<div class="accordion panel-group col-md-12" role="tablist" aria-multiselectable="true">
<div class="accordion__item">
<a class="accordion__item__header" role="button" data-toggle="collapse" data-target="#accordion-#guid" aria-expanded="false" aria-controls="accordion-#guid">
#item.Title
</a>
<div class="collapse" id="accordion-#guid">
<div class="accordion__item__body">
#item.Description
</div>
</div>
</div>
</div>
}
}
</div>
</div>
</section>
And this is the result on one of the pages:
All the accordions have a different control-id thanks to the guid. Any idea why it doesn't count up?
How is it auto numbering? I don't see an OL or anything that would auto-number. Seems like the number is just part of the item.Title? If that is this case, you could do something like this.
#if(Model.Content.Accordion != null && Model.Content.Accordion.Any())
{
var counter == 1;
foreach (var item in Model.Content.Accordion)
{
var guid = Guid.NewGuid();
<div class="accordion panel-group col-md-12" role="tablist" aria-multiselectable="true">
<div class="accordion__item">
<a class="accordion__item__header" role="button" data-toggle="collapse" data-target="#accordion-#guid" aria-expanded="false" aria-controls="accordion-#guid">
#(counter + ". " + #item.Title)
</a>
<div class="collapse" id="accordion-#guid">
<div class="accordion__item__body">
#item.Description
</div>
</div>
</div>
</div>
#counter++;
}
}
I managed to get the code working. I moved one of the div's outside the if code and it worked. Not sure why the div made the accordions count though. Thanks to hardba11 and ADyson for trying to help!
<div class="accordion panel-group col-md-12" role="tablist" aria-multiselectable="true">
#if(Model.Content.Accordion != null && Model.Content.Accordion.Any())
{
foreach (var item in Model.Content.Accordion)
{
var guid = Guid.NewGuid();
<div class="accordion__item">
<a class="accordion__item__header" role="button" data-toggle="collapse" data-target="#accordion-#guid" aria-expanded="false" aria-controls="accordion-#guid">
#item.Title
</a>
<div class="collapse" id="accordion-#guid">
<div class="accordion__item__body">
#item.Description
</div>
</div>
</div>
}
}
</div>

Replacing jQuery UI Accordion to Bootstrap Accordion(or equivalent)

Right now we are using the jQuery UI Accordion control for our drilldowns and we are in a process of changing to Bootstrap equivalent Accordion control. So I would like to know the best practices to do so. Please advice and thanks in advance.
Following is the html used for jQuery UI Accordion
#foreach (Xyz.MenuItem menu in Model)
{
if (menu.Items.Count() > 0)
{
<div class="accordion">
<h3>
#Html.ActionLinkForMenu(menu, true, null)
</h3>
<ul>
#foreach (Xyz.MenuItem subMenu in menu.Items)
{
<li>#Html.ActionLinkForMenu(subMenu, false, null)</li>
}
</ul>
</div>
}
else
{
#Html.ActionLinkForSingleMenu(menu, new { #class = "home" })
}
}
An example would be a Great Help.
Just follow the manual from bootstrap and rewrite your form like this
<div class="panel-group" id="accordion">
#foreach (Xyz.MenuItem menu in Model)
{
if (menu.Items.Count() > 0)
{
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
#Html.ActionLinkForMenu(menu, true, null)
</a>
</h3>
</div>
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body">
#foreach (Xyz.MenuItem subMenu in menu.Items)
{
<li>#Html.ActionLinkForMenu(subMenu, false, null)</li>
}
</div>
</div>
</div>
}
else
{
#Html.ActionLinkForSingleMenu(menu, new { #class = "home" })
}
}
</div>

knockout.js modal binding value update

I have the following code in this jsFiddle.
The problem I'm having is that my child items do not update properly.
I can Click "Edit User" with a problem and see the data changing, but when I attempt to add a note or even if I were to write an edit note function, the data does not bind properly
http://jsfiddle.net/jkuGU/10/
<ul data-bind="foreach: Users">
<li>
<span data-bind="text: Name"></span>
<div data-bind="foreach: notes">
<span data-bind="text: text"></span>
Edit Note
</div>
Add Note
Edit user
</li>
</ul>
<div id="userModal" data-bind="with: EditingUser" class="fade hjde modal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>
Editing user</h3>
</div>
<div class="modal-body">
<label>
Name:</label>
<input type="text" data-bind="value: Name, valueUpdate: 'afterkeydown'" />
</div>
<div class="modal-footer">
Save changes
</div>
</div>
<div id="addJobNoteModal" data-bind="with: detailedNote" class="fade hjde modal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>
Editing Note</h3>
</div>
<div class="modal-body">
<label>
Text:</label>
<input type="text" data-bind="value: text, valueUpdate: 'afterkeydown'" />
</div>
<div class="modal-footer">
Save changes
</div>
</div>
​
function Note(text) {
this.text = text;
}
var User = function(name) {
var self = this;
self.Name = ko.observable(name);
this.notes = ko.observableArray([]);
}
var ViewModel = function() {
var self = this;
self.Users = ko.observableArray();
self.EditingUser = ko.observable();
self.detailedNote = ko.observable();
self.EditUser = function(user) {
self.EditingUser(user);
$("#userModal").modal("show");
};
this.addNote = function(user) {
var note= new Note("original")
self.detailedNote(note);
$("#addJobNoteModal").find('.btn-warning').click(function() {
user.notes.push(note);
$(this).unbind('click');
});
$("#addJobNoteModal").modal("show");
}
for (var i = 1; i <= 10; i++) {
self.Users.push(new User('User ' + i));
}
}
ko.applyBindings(new ViewModel());​
Change this:
$("#addJobNoteModal").find('.btn-warning').click(function() {
To this:
$("#addJobNoteModal").find('.btn-primary').click(function() {
You were targetting the wrong button :)
I think the problem after all was that you must bind to "value:" not "text:" in a form input/textarea.

Resources