Mvc partial view reload or refresh - asp.net-mvc-2

i have a view called Index with 4 partial view like _tab1,_tab2,_tab3 and _tab4 , each partial view has form fields including submit and cancel button, when i click on _tab4 cancel button i want to reload the same _tab4 partial view with form data cleared.
<ul class="tab">
<li class="active" id="tab1">tab1</li>
<li class="" id="tab2">tab2</li>
<li class="" id="tab3">tab3</li>
<li class="" id="tab4">tab4</li>
</ul>
<div class="tabbody" style="display: block; ">
<% Html.RenderPartial("_tab1"); %>
</div>
<div class="tabbody"style="display: block; ">
<% Html.RenderPartial("_tab2"); %>
</div>
<div class="tabbody"style="display: block; ">
<% Html.RenderPartial("_tab3"); %>
</div>
<div class="tabbody" style="display: block; ">
<% Html.RenderPartial("_tab4"); %>
</div>
Each partial view has submit and cancel button

Mark each of your divs with unique id:
<div id="tab1-content" class="tabbody" style="display: block; ">
<% Html.RenderPartial("_tab1"); %>
</div>
Execute some jQuery code on cancel button click function:
$("cancelTab1buttonselector").click(function() {
$.get("#Html.Action("Tab1")", function(data) {
$("#tab1-content").html(data);
});
});
Where "cancelTab1buttonselector" is selector for cancel button in tab1. Do same for each tab.
You need to create controller's actions returning each tab content as PartialViewResult:
public ActionResult Tab1()
{
var model = ...get model...
return PartialView("_tab1", model);
}

Try just load ur partials to the wrapper with data check attribute
html:
<ul class="tab">
<li class="active tab" id="tab1" data-tabid="tab1">tab1</li>
<li class="tab" id="tab2" data-tabid="tab2">tab2</li>
<li class="tab" id="tab3" data-tabid="tab3">tab3</li>
<li class="tab" id="tab4" data-tabid="tab4">tab4</li>
</ul>
<div class="tabbody" style="display: block; ">
<% Html.RenderPartial("_tab1"); %>
</div>
jquery :
$(document).on('click','.tab',function(){
var tabId = $(this).data('tabid');
if(tabId=='tab1'){
$('.tabbody').empty().load('/Controller/_tab1');
}
if(tabId=='tab2'){
$('.tabbody').empty().load('/Controller/_tab2');
}
if(tabId=='tab3'){
$('.tabbody').empty().load('/Controller/_tab3');
}
if(tabId=='tab4'){
$('.tabbody').empty().load('/Controller/_tab4');
}
});

Related

Delegated EventHandler - specific modal depending on tab - Active

I'm wanting to display one of three modals upon the click of one button in the navbar, depending on which of the the three tabs is active. I am trying to use the delegated eventhandler, however my computer skills are relatively immature and I am getting all three modals come up.
The modal ids are id="createModal", "createModalD" and "createModalL" for the employee, department and location data.
//SHOW ADD EMPLOYEE MODAL
$("nav").on("click", "#Ebutton", function (e) {
e.preventDefault();
$("#createModal").modal("show");
//$("#createModal").modal("");
});
$(".nav-tab loc").on("click", "createModal", function (e) {
$("#createModalD").modal("hide");
$("#createModalL").modal("hide");
});
//SHOW ADD DEPARTMENT MODAL
$("nav").on("click", ".Dbutton", function (e) {
e.preventDefault();
$("#createModalD").modal("show");
//$("#createModalD").modal("");
});
$(".Dbutton").on("click", "createModalD", function (e) {
$("#createModalL").modal("hide");
$("#createModal").modal("hide");
});
// //SHOW ADD LOCATION MODAL
$("nav").on("click", "#Ebutton", function (e) {
e.preventDefault();
$("#createModalL").modal("show");
// $("#createModalL").modal("");
});
$("#Ebutton").on("click", "createModalL", function (e) {
$("#createModalD").modal("hide");
$("#createModal").modal("hide");
});
!-- NAVIGATION BAR -->
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
<div class="container">
<!-- Add Button -->
<button role="button" class="Dbutton"id="Ebutton"><i class="fas fa-plus"></i></button>
<button class="navbar-toggler fixed" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse " id="navbarSupportedContent">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="index-tab" data-bs-toggle="tab" data-bs-target="#index" type="button" role="tab" aria-controls="index" aria-selected="true">Employee</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link " id="department-tab" data-bs-toggle="tab" data-bs-target="#department" type="button" role="tab" aria-controls="department" aria-selected="false">Department</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="loc-tab" data-bs-toggle="tab" data-bs-target="#loc" type="button" role="tab" aria-controls="loc" aria-selected="false">Location</button>
</li>
</ul>
</div>
</nav>

Sugarcrm 7 Custom view with tabs

i implement the following custom view
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" data-target="tab1">Section 1</a></li>
<li><a data-toggle="tab" data-target="tab2">Section 2</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab1">
<p>I'm in Section 1.</p>
</div>
<div class="tab-pane" id="tab2">
<p>Howdy, I'm in Section 2.</p>
</div>
</div>
</div>
<script>
$( function() {
$('.nav-tabs a').click(function(){
console.log(this);
$(this).tab('show');
});
} );
</script>
The tabs are showing correctly but when i click tab2 the tab is not changing to content of of tab2. Console.log is shown. Any help please ?
The IDs provided in data-target are missing a leading # each.
Values of the data-target attribute are parsed as jquery selectors.
<li class="active"><a data-toggle="tab" data-target="#tab1">Section 1</a></li>
<li><a data-toggle="tab" data-target="#tab2">Section 2</a></li>

Displaying a single document from a mongo database?

I use ejs to display the information but I am having trouble displaying only one document. I would like to display one document until user clicks the next button.
View:
<div>
<h1>This is the movie page</h1>
<ul>
<% for(var i =0; i < movies.length; i ++) {%>
<li>
<span style="font-weight: bold">Title:</span> <%= movies[i].DVD_Title %>
</li>
<li>
<span style="font-weight: bold">Studio:</span> <%= movies[i].Studio %>
</li>
<li>
<span style="font-weight: bold">Genre:</span> <%= movies[i].Genre %>
</li>
<li>
<span style="font-weight: bold">Year:</span> <%= movies[i].Year %>
</li>
<br>
<% } %>
<button type="button" id="prev">Prev </button>
<button type="button" id="next">Next</button>
</ul>
</div>
Controller:
var express = require('express');
var router = express.Router();
var moviesModel = require("../models/movies");
/* GET /movies/ listing. */
router.get('/', function(req, res, next) {
moviesModel.find({}).where('Price').gt(10000).exec(function(err,movies){
if(err) throw err;
res.render('movies', {movies:movies});
});
});
module.exports = router;
Link to my repo found here.
Thanks!
Since the mongodb query data is returned to the view as an json objects I cannot increment it. I have to push it to its own array and increment that.
Here is my new view:
<div>
<h1>This is the movie page</h1>
<ul>
<% var movieArray = new Array();
for(var i =0; i < movies.length; i ++) {
movieArray.push(movies[i]);
}
var x = 0;
%>
<li>
<span style="font-weight: bold">Title:</span> <%= movieArray[x].DVD_Title %>
</li>
<li>
<span style="font-weight: bold">Studio:</span> <%= movieArray[x].Studio %>
</li>
<li>
<span style="font-weight: bold">Genre:</span> <%= movieArray[x].Genre %>
</li>
<li>
<span style="font-weight: bold">Year:</span> <%= movieArray[x].Year %>
</li>
<br>
<h1><%= movieArray.length %></h1>
<button type="button" id="prev" onClick="prev_movie">Prev </button>
<button type="button" id="next" onClick="next_movie">Next</button>
</ul>
</div>
Once Prev or Next is pushed the x value will decrease or increase unless user reaches -1 or array.length.

How to add HTML without a DIV (GWT)

I'm trying to create a menu dynamically (with some data from my database), the problem occurs when i try to add new menu item "li" with gwt HTML composite or with HTMLPanel, the li added inside a div element! and that break my style and break the menu, what can do to add html without div in gwt??
<ul style="display: none;" id="agence-id" class="submenu">
<div class="gwt-HTML">
<li>
<a id="P45O421">
<i class="icon-double-angle-right">
</i>P45O421</a>
</li>
</div>
<div class="gwt-HTML">
<li>
<a id="c2">
<i class="icon-double-angle-right">
</i>c2
</a>
</li>
</div>
<div class="gwt-HTML">
<li>
<a id="c3">
<i class="icon-double-angle-right"></i>c3</a>
</li>
</div>
<div class="gwt-HTML">
<li>
<a id="c4">
<i class="icon-double-angle-right">
</i>c4</a>
</li>
</div>
Create the HTMLPanel with the constructor where you can set the tag: HTMLPanel("li", yourHTML);. This will use the li instead of the standard div.
You can create Li elements by using dete Document.get().createLIElement() method and then add them to your ul element.
When you call RootPanel.get("YOURID").you get the ul element, since you have given it an id and therefor can find it in the DOM:
Codeexample:
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.LIElement;
...
HeadingElement liElement = Document.get().createLIElement();
liElement.setInnerText("This is a Li(l1) element!");
RootPanel.get("agence-id").getElement().appendChild(liElement );

jquery on show and on hide not working with class selector

I am trying to enter certain roles in a text area and have it highlighted in a popup block using bootstrap.
The expected behavior is that the selected roles must be highlighted, the code works when I use the id selector to the jquery, but the same code does not work with class selector
<textarea name="options" id="options" cols="30" rows="10">admin user</textarea>
<a class="btn" data-toggle="modal" href="#myModal">Launch Modal</a>
<div class="modal hide fade" id="myModal" class="myModal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Modal header</h3>
</div>
<div class="modal-body">
<div>
<ul>
<li class="mlist">admin</li>
<li class="mlist">user</li>
<li class="mlist">guest</li>
<li class="mlist">blank</li>
</ul>
</div>
</div>
<div class="modal-footer">
Close
</div>
</div>
<script type="text/javascript">
$(document).ready(function (){
console.log('Inside onready');
$('.myModal').on('show', function () {
console.log('Inside show');
var option = $('#options').val();
var options = option.split(" ");
console.log('Selected roles: ' + options);
for (var index = 0; index < options.length; index++) {
highlight(options[index]);
};
});
$('.myModal').on('hide', function () {
console.log('Inside onhide');
$('.mlist').removeClass('btn-primary');
});
});
function highlight(parOptions) {
$('.mlist:contains("' + parOptions +'")').addClass('btn-primary');
}
</script>
I guess it's something to do with your div having two class tags.
<div class="modal hide fade" id="myModal" class="myModal">
Change to
<div class="modal hide fade myModal" id="myModal">