MVC Project memory leaking, how to fix it? - asp.net-mvc

I've tried everything about that but i couldnt find a solution. On local, there's no problem. But when i publish to provider hosting. Memory leaking issue is coming out and IIS Recylcling every 75 seconds. I Used memory profiler but, no issue on local like i said. Here's my basecontroller code. Can it cause a memory leak?. And i use tags in layout. Maybe it causes a memory leak. If you want layout code i can add. For now, my basecontroller code be like;
public class BaseController : Controller
{
public BaseController()
{
GC.Collect(2, GCCollectionMode.Forced, true);
GC.WaitForPendingFinalizers();
}
internal void ShowErrorMessage(string message)
{
ViewBag.ErrorMessage = message;
}
public List<Categories> GetCategories()
{
var catserv = new CategoryService();
return catserv.GetAll().Where(x => x.Status == DataStatus.Active).ToList();
}
public List<Products> GetProducts()
{
var prodserv = new ProductService();
return prodserv.GetAll().ToList();
}
public bool CheckAdmin()
{
string username = User.Identity.Name;
var member = new MemberService();
var result = member.GetUserName(username);
if (result.Data.IsAdmin != 1)
return false;
else
return true;
}
public string SamePath()
{
return Request.UrlReferrer.PathAndQuery.ToString();
}
}
GetCategories method is being used for layout. I couldnt add viewmodel entity and i added this method below.
Check my admincontroller and layout.
[HttpPost]
public ActionResult Login(Member memb)
{
var memberservice = new MemberService();
var getMemberResult = memberservice.Auth(memb.UserName, memb.Password);
if (getMemberResult.HasError)
{
ViewBag.mesaj = getMemberResult.ResultMessage;
return View();
}
if (getMemberResult.Data.Status == DataStatus.Banned)
{
return RedirectToAction("BannedUser");
}
FormsAuthentication.SetAuthCookie(getMemberResult.Data.UserName, false);
return RedirectToAction("Anasayfa", "Magaza");
}
And my layout.. and actually it has var baseController = ViewContext.Controller as web2.Controllers.BaseController; on the top
<body>
<div class="banner_bg_main">
<!-- header top section start -->
<div class="container">
<div class="header_section_top">
<div class="row">
<div class="col-sm-12">
<div class="custom_menu">
<ul>
<li>Kusursuz Tasarım</li>
<li>Profesyonel Çalışmalar</li>
<li>Uygun Fiyat Politikası</li>
<li>Promosyon Ürünleri</li>
<li>Matbaa Ürünleri</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<!-- header top section start -->
<!-- logo section start -->
<div class="logo_section">
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="logo"></div>
</div>
</div>
</div>
</div>
<!-- logo section end -->
<!-- header section start -->
<div class="banner_section layout_padding">
<div class="container">
<div id="my_slider" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<div class="row">
<div class="col-sm-12">
<h1 class="banner_taital">%100<br>Fiyat Garantisi</h1>
<div class="buynow_bt">Sipariş Ver</div>
</div>
</div>
</div>
<div class="carousel-item">
<div class="row">
<div class="col-sm-12">
<h1 class="banner_taital">Hemen Ürün<br>Siparişinizi Verin</h1>
<div class="buynow_bt">Sipariş Ver</div>
</div>
</div>
</div>
<div class="carousel-item">
<div class="row">
<div class="col-sm-12">
<h1 class="banner_taital">Tamamen isteğe<br>UYGUN TASARIM</h1>
<div class="buynow_bt">Sipariş Ver</div>
</div>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#my_slider" role="button" data-slide="prev">
<i class="fa fa-angle-left"></i>
</a>
<a class="carousel-control-next" href="#my_slider" role="button" data-slide="next">
<i class="fa fa-angle-right"></i>
</a>
</div>
</div>
</div>
<div class="header_section pb-3">
<div class="container">
<div class="containt_main justify-content-center">
<div id="mySidenav" class="sidenav">
×
<a href=#Url.Action("Anasayfa","Magaza")>Anasayfa</a>
<a href=#Url.Action("Urunler","Magaza")>Ürünler</a>
#if (User.Identity.IsAuthenticated)
{
<a href=#Url.Action("Menu","Admin")>Admin Menü</a>
}
</div>
</div>
<div class="containt_main">
<span class="toggle_icon" onclick="openNav()"><img src="~/Content/images/toggle-icon.png"></span>
<div class="main">
<!-- Another variation with a button -->
#using (Html.BeginForm("Urunler", "Magaza", FormMethod.Get))
{
<div class="input-group">
#Html.TextBox("Ara", "", new { #class = "form-control", #placeholder = "Ürün Arayın", #type = "text" })
<div class="input-group-append">
<button class="btn btn-secondary" type="submit" style="background-color: #f26522; border-color:#f26522">
<i class="fa fa-search"></i>
</button>
</div>
</div>
}
</div>
<div class="header_box">
<div class="login_menu">
<!--<ul>
<li><a href="#">
<i class="fa fa-shopping-cart" aria-hidden="true"></i>
<span class="padding_10">Cart</span></a>
</li>
<li><a href="#">
<i class="fa fa-user" aria-hidden="true"></i>
<span class="padding_10">Cart</span></a>
</li>
</ul> -->
</div>
</div>
</div>
<div class="text-center mt-3">
<button class="btn btn-secondary dropdown-toggle mb-3" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Kategoriler
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
#foreach (var item in baseController.GetCategories())
{
<a class="dropdown-item" href="#Url.Action("Urunler","Magaza", new {#kategori = item.Id })">#item.CategoryName</a>
}
</div>
</div>
</div>
</div>
<!-- header section end -->
<!-- banner section start -->
<!-- banner section end -->
</div>
#RenderBody()
<div class="footer_section layout_padding">
<div class="container">
<div class="footer_logo"><img style="height:100px;" src="~/Content/img/logo.png"></div>
<div class="footer_menu">
<ul>
<li>
<li>Uygun Fiyat Politikası</li>
<li>%100 Memnuniyet</li>
</ul>
<br />
<ul>
<li>Anasayfa</h3></li>
</ul>
<br />
<ul>
<li><h3 style="color:white">Adres</h3>Rami Cuma Mah.<br /> Oruç Sk. No:20B<br />Eyüp/İstanbul</li>
</ul>
</div>
<div class="location_main">Whatsapp Hattı İçin Tıkla</div>
<div class="location_main"><img class="img-responsive" style="height:55px;" src="~/Content/img/instalogo.png" /></div>
</div>
</div>
<script src="~/Content/js/jquery.min.js"></script>
<script src="~/Content/js/bootstrap.bundle.min.js"></script>
<script src="~/Content/js/jquery-3.0.0.min.js"></script>
<script src="~/Content/js/plugin.js"></script>
<!-- sidebar -->
<script src="~/Content/css/jquery.mCustomScrollbar.concat.min.js"></script>
<script src="~/Content/css/custom.js"></script>
<script type="text/javascript" src="~/Content/js/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2#10"charset="utf-8"></script>
<script>
var counter = 0;
function openNav() {
counter++;
if (counter % 2 == 1)
document.getElementById("mySidenav").style.width = "250px";
else
document.getElementById("mySidenav").style.width = "0";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
#if (ViewBag.ErrorMessage != null || TempData["Fail"] != null)
{
<script>
swal.fire({
title: "Olmadı be",
text: '#ViewBag.ErrorMessage',
icon: "error",
});
</script>
}
#if (ViewBag.successtoindex != null)
{
<script>
swal.fire({
icon: 'info',
title: 'Hadi Anasayfaya Dönelim',
text: '#ViewBag.successtoindex',
button: 'Hadi Anasayfaya Dönelim!'
}).then(function () {
window.location = "/";
});
</script>
}
#if (ViewBag.success != null || TempData["Success"] != null)
{
<script>
swal.fire({
title: "Mükemmel",
text: '#ViewBag.success',
icon: "success",
button: "Aww yiss!",
});
</script>
}
#if (ViewBag.successadminmenu != null)
{
<script>
swal.fire({
title: "Başarılı",
text: '#ViewBag.successadminmenu',
icon: "success",
button: "Muhteşem!",
}).then(function () {
window.location = "menu";
});;
</script>
}

Related

jquery / Ajax "undefined" error

i am trying to get an image uploader working inside my MVC project, but everytime i click the upload file button, i get "Error undefined", i am not sure where i am going wrong.
The page is a partial view, loaded inside a #Html.BeginForm . below is the code i am using.
Index.cshtml
#using (Html.BeginForm("Register", "Account", FormMethod.Post))
{
#Html.AntiForgeryToken()
<div class="container">
<div class="row">
<article class="col-sm-12 col-md-12 col-lg-12 sortable-grid ui-sortable">
<div id="wid-id-0">
<!-- widget div-->
<div role="content">
<!-- widget content -->
<div class="widget-body">
<div class="row" style="background: white">
<form id="wizard-1" novalidate="novalidate">
<div id="bootstrap-wizard-1" class="col-sm-12">
<div class="tab-content">
#*Tab 1 (Step 1)*#
<div class="tab-pane active" id="tab1">
<br>
#Html.Partial("Registration/_Step1")
<div class="form-actions">
<div class="row">
<div class="col-sm-12">
<ul class="pager wizard no-margin">
<li class="previous disabled">
Previous
</li>
<li data-target="#step2" class="next">
Next
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="form-bootstrapWizard">
<ul class="bootstrapWizard form-wizard" style="background: coral">
<li class="active" data-target="#step1">
<span class="step">1</span> <span class="title">Step 1: Profile Information</span>
</li>
<li data-target="#step2" class="">
<span class="step">2</span> <span class="title">Step 2: Profile Picture</span>
</li>
<li data-target="#step3" class="">
<span class="step">3</span> <span class="title">Step 3: Identification</span>
</li>
<li data-target="#step4">
<span class="step">4</span> <span class="title">Step 4: Submit Profile</span>
</li>
</ul>
<div class="clearfix"></div>
</div>
</div>
</form>
</div>
</div>
<!-- end widget content -->
</div>
<!-- end widget div -->
</div>
<!-- end widget -->
</article>
</div>
</div>
}
_Step1.cshtml
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$(document).ready(function () {
$("#Upload").click(function (e) {
e.preventDefault();
var formData = new FormData();
var totalFiles = document.getElementById("FileUpload").files.length;
for (var i = 0; i < totalFiles; i++)
{
var file = document.getElementById("FileUpload").files[i];
formData.append("FileUpload", file);
}
$.ajax({
type: "POST",
url: '#Url.Action("UploadFiles", "Account")',
data: formData,
dataType: 'json',
contentType: false,
processData: false,
success: function (response) {
alert('succes!!');
},
error: function (error) {
alert("error: " + error.statusMessage);
}
});
});
});
</script>
<table align="center">
<tr>
<td style="text-align: center;"><label>Upload Profile Picture</label></td>
<td></td>
</tr>
<tr>
<td valign="top"><img id="imgPreview" src="~/Content/Images/upload_holder.PNG" class="img-holder" style="width: 180px; height: 180px;" /></td>
<td>
#*<input type="submit" class="btn btn-lg" style="width: 200px; background: #0091d9; color: white;" value="Upload Photo" />*#
#*<input id="input-4" name="input4[]" type="file" multiple class="file-loading" style="width: 200px; background: #0091d9; color: white;" value="Upload Photo">*#
<input type="file" id="FileUpload" multiple />
<input type="submit" id="Upload" value="Upload"/>
<br />
<br />
<label>Acceptable file formats: jpg, gif or png file</label>
<br />
<label>Under 1 MB</label>
</td>
</tr>
</table>
any help is greatly appreciated!
EdIT: Below is the controller function, but its never hit.
[HttpPost]
public ActionResult UploadFiles()
{
// Checking no of files injected in Request object
if (Request.Files.Count > 0)
{
try
{
// Get all files from Request object
HttpFileCollectionBase files = Request.Files;
for (int i = 0; i < files.Count; i++)
{
//string path = AppDomain.CurrentDomain.BaseDirectory + "Uploads/";
//string filename = Path.GetFileName(Request.Files[i].FileName);
HttpPostedFileBase file = files[i];
string fname;
// Checking for Internet Explorer
if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
{
string[] testfiles = file.FileName.Split(new char[] { '\\' });
fname = testfiles[testfiles.Length - 1];
}
else
{
fname = file.FileName;
}
// Get the complete folder path and store the file inside it.
fname = Path.Combine(Server.MapPath("~/Uploads/"), fname);
file.SaveAs(fname);
}
// Returns message that successfully uploaded
return Json("File Uploaded Successfully!");
}
catch (Exception ex)
{
return Json("Error occurred. Error details: " + ex.Message);
}
}
else
{
return Json("No files selected.");
}
}

Jquery How to like switch to next tab in ASP MVC5

I have a view like this
View Code:-
<div class="col-md-3" style="background-color:white" id="Tabs">
<ul class="nav nav-tabs tabs-left">
<li class="active"><a data-toggle="tab" href="#home">Home</a></li>
<li><a data-toggle="tab" href="#menu1">Menu 1</a></li>
</ul>
</div>
<div class="col-md-9 tabs-left" style="background-color:white">
<div class="tab-content">
<div id="home" class="tab-pane fade in active">
<div class="panel-body fixed-panel">
<div class="row">
<div class="col-lg-3">
#Html.DropDownList("List", new SelectList(ViewBag.List, "ListID", "ListDescription"), "Select", new { id = "List1"})
</div>
Continue
</div>
</div>
</div>
<div id="menu1" class="tab-pane fade in active">
<div class="panel-body fixed-panel">
<div class="row">
<div class="col-lg-3">
#Html.DropDownList("List", new SelectList(ViewBag.List, "ListID", "ListDescription"), "Select", new { id = "List1"})
</div>
</div>
</div>
</div>
<div id="menu2" class="tab-pane fade in active">
<div class="panel-body fixed-panel">
<div class="row">
<div class="col-lg-3">
#Html.DropDownList("List", new SelectList(ViewBag.List, "ListID", "ListDescription"), "Select", new { id = "List1"})
</div>
</div>
</div>
</div>
</div>
</div>
"
Jquery To check for validation and close the tab and open the next tab:-
$('.nexttab').click(function (e) {
e.preventDefault();
var sectionValid = true;
section = $(this).closest('.tab-pane.fade');
$.each(section.find('input'), function () {
if (!$(this).valid()) {
sectionValid = false;
}
});
if (sectionValid) {
// collapse current section:
section.collapse('toggle');
// find and uncollapse next section:
section.next().find('.tab-pane.fade').collapse('toggle');
}
});
I have go to close the active tab by "section.collapse('toggle');" however not able to open the next on on clicking the next tab. Any help will be highly appreciated. I am still trying my hands at asp mvc,so i could have missed the obvious.
Try this. I cleaned up the tab markup a bit, wrapped it with a form (required by jquery validate) and used .tab() instead of .collapse().
See http://getbootstrap.com/javascript/#tabs for the relevant documentation.
$('.nexttab').click(function(e) {
e.preventDefault();
var sectionValid = true;
section = $(this).closest('.tab-pane.fade');
sectionValid = section.closest('form').valid();
if (sectionValid) {
// find and uncollapse next section:
$(".nav-tabs .active a").closest("li").next().find("a").tab("show");
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.jsdelivr.net/jquery.validation/1.15.0/jquery.validate.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<form>
<ul class="nav nav-tabs tabs-left">
<li class="active"><a data-toggle="tab" href="#home">Home</a>
</li>
<li><a data-toggle="tab" href="#menu1">Menu 1</a>
</li>
</ul>
<div class="tab-content">
<div id="home" class="tab-pane fade in active">
<div class="panel-body fixed-panel">
<div class="row">
<div class="col-lg-3">
</div>
Continue
</div>
</div>
</div>
<div id="menu1" class="tab-pane fade in active">
<div class="panel-body fixed-panel">
<div class="row">
<div class="col-lg-3">
</div>
</div>
</div>
</div>
<div id="menu2" class="tab-pane fade in active">
<div class="panel-body fixed-panel">
<div class="row">
<div class="col-lg-3">
</div>
</div>
</div>
</div>
</div>
</form>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
You should be using the .tab('show') instead of .collapse('toggle').

ReactJS.NET : Unable to get click events to fire

I'm running ReactJS.NET with ASP.NET MVC, and everything renders well, except... i cannot get any kind of events to fire...
What i have tried :
1) Eliminating all JQuery references/usages - no success
2) onHover, onClick, with functions both inside and outside of the React-component - no success
Here is my code :
Attaching ProductLine React component in index.cshtml
#Html.React("ProductLine", Model)
React component
function addToCart() {
alert("Hoohohoho!!!");
};
var ProductLine = React.createClass({
render: function () {
return(
<div className="col-md-12 col-sm-12 col-xs-12" key={this.props.productData.name}>
<button onClick={this.addToCart}>Click me!</button>
<div className="row" >
<div onClick={addToCart} className="col-md-12 col-sm-12 col-xs-12 nopadding row-default" >
<div className="col-md-3 col-sm-5 col-xs-5 nopadding">
<span className="table table-col ">
<input type="checkbox" id="cbxCheck2" className="jq_select_product" />
<label htmlFor="cbxCheck2" className="jq_select_product">{ this.props.productData.name }</label>
</span>
</div>
<div className="col-md-4 hidden-sm hidden-xs nopadding">
<span className="table table-col table-text-small">
{ this.props.productData.label }
</span>
</div>
<div className="col-md-3 col-sm-4 col-xs-4 nopadding">
<span className="table table-col">
849,- (12 mnd)
</span>
</div>
<div className="col-md-2 col-sm-3 col-xs-3 nopadding">
<span className="table table-col table-text-small text-right">
<img id="imgShowMore" src="../../Images/arrow_purple_down.png" className="show-more _icon jq_expand_listview" /><label className="show-more _lbl jq_expand_listview">Vis mer</label>
</span>
</div>
</div>
<ProductDetails productData={this.props.productData} />
</div>
</div>
);
},
addToCart: function (e) {
alert("Hooooo!!!");
},
});
After 1/2 a day of trial and error, i suddenly tried to put all the JSX file references at the bottom of the _Layout.cshtml page...
That solved it all actually...

The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/SiteLayout.cshtml": "Scripts"

I have a simple view:
#model BootstrapTest4.Models.Account.CambioDeClave
#{
Layout = "~/Views/Shared/SiteLayout.cshtml";
}
<h2>#Model.Title</h2>
#using (Html.BeginForm()) {
#Html.AntiForgeryToken()
#Html.ValidationSummary(true)
<fieldset>
<div class="editor-label">
#Html.LabelFor(model => model.Pass1)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.Pass1)
#Html.ValidationMessageFor(model => model.Pass1)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.Pass2)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.Pass2)
#Html.ValidationMessageFor(model => model.Pass2)
</div>
<p>
<input type="submit" value="Cambiar Clave" />
</p>
</fieldset>
}
#section Scripts {
#System.Web.Optimization.Scripts.Render("~/bundles/jqueryval")
}
this view was made via the Mvc4 scaffolding system (edit template) and since I use some dataannotations in my model it uses the Scripts Bundle.
the error I am getting is the following:
The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/SiteLayout.cshtml": "Scripts"
searching I found that most people solve the problem adding this to their layout:
#if (IsSectionDefined("Scripts"))
{
RenderSection("Scripts",false);
}
I added that block just before the tag of my layout but i still get the same error.
as requested: my whole Layout:
#model BootstrapTest4.Models.IMenu
#using BootstrapTest4.Utils.Helpers
#using BootstrapTest4.Utils
#{
Layout = null;
}
<!DOCTYPE html>
#{
Model.usr = (UsuarioWebCliente)Session["DatosUsr"];
Model.usrDrogSelec = Html.DrogSeleccionada(Model.usr);
var Lista = Html.GeneraComboDrogs2(Model.usr, Model.usrDrogSelec.cod_drogueria);
}
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>#ViewBag.Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="~/Scripts/jquery-1.9.1.js"></script>
<script src="~/Scripts/bootstrap.js"></script>
<!-- Bootstrap -->
<link href="~/Content/bootstrap/bootstrap.css" rel="stylesheet" media="screen">
</head>
<body style="height: 100%; ">
<div class="wrapper">
<div>
<div id="whitebar">
<div class="container">
<div class="row">
<div class="col-md-6">
</div>
<div class="col-md-6" style="text-align: right">
#Model.usr.DatUsrs.desc_usuario - #Model.usr.DatUsrs.codigo_ident - #Html.ActionLink("Cerrar Sesion","Logout","Account")
</div>
</div>
</div>
</div>
<div id="bluebar">
<div class="container">
<div class="row">
<div class="col-md-4">
#Html.DropDownListFor(x => x.usr.DatUsrs.cod_drogueria, new SelectList(Lista, "Value", "Text"), new { #id = "DDLMENU", data_url = Url.Action("CambiarDrog", "Menu") })
</div>
<div class="col-md-3">
Monto Consumido:
<label id="SALDO">
#(Model.usrDrogSelec.saldo_actual == 0 ? "0.00" : Convert.ToDecimal(Model.usrDrogSelec.saldo_actual).ToString("#,##.00"))
</label>
</div>
<div class="col-md-3">
Hora Corte: XXXXX
</div>
<div class="col-md-2">
Día Corte:
<label id="DIA">
#Model.usrDrogSelec.dia_corte
</label>
</div>
</div>
</div>
</div>
<nav class="navbar navbar-default" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">
<img style="max-height: 20px;" src="~/Content/Images/1381797224_home.png" />
</a>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
#foreach (var item in Model.MenuCollection)
{
<li class="dropdown">
#item.Name <b class="caret"></b>
#if (item.Children.Count > 0)
{
<ul class="dropdown-menu">
#foreach (var childItem in item.Children)
{
<li>#Html.ActionLink(childItem.Name, childItem.Action, childItem.Controller)</li>
}
</ul>
}
</li>
}
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<span class="glyphicon glyphicon-cog"></span><b class="caret"></b>
<ul class="dropdown-menu">
<li>#Html.ActionLink("Droguería Principal","PrioridadDrogueria","ReportesPrioridadDrogueria")</li>
<li>Mensajería </li>
<li> #Html.ActionLink("Cambio de Clave", "CambiarClave", "Account")</li>
<li>Actualizar Datos</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</nav>
<div id="Content" style="height: 100%; ">
#RenderBody()
</div>
</div>
<div class="push"></div>
</div>
<div class="footer">
<div class="row">
<div class="col-md-12 footer">Test</div>
</div>
</div>
#if (IsSectionDefined("Scripts"))
{
RenderSection("Scripts",false);
}
</body>
</html>
Did you try only
RenderSection("Scripts",false);
Instead of
#if (IsSectionDefined("Scripts"))
{
RenderSection("Scripts",false);
}
You should just call RenderSection.
#RenderSection("Scripts", false)
I got the following error while running the application I resolved it by adding #RenderSection(“Scripts”,required:false) in the _Layout page.
#RenderSection("scripts", required: false)

How to put jqm data-role="page" in a MVC view page?

I'm using MVC3 to create a beta mobile web app. It was working fine until I started to try and get inline pages inside of a view similar to this
This is what I currently have in my view called Index. How come when I click the links in the navbar it doesn't go to the page?
#model List<ShawGoVersion1.Models.NewsItem>
#{
ViewBag.Title = "News";
}
#section Header {
#Html.ActionLink("Back", "Index", "Home", null, new { data_icon = "arrow-l"})
<h1>#ViewBag.Title</h1>
<div data-role="navbar">
<ul>
<li>My News</li>
<li>Press Releases</li>
<li>All News</li>
</ul>
</div>
}
<div data-role="page" id="MyNews">
<div data-role="content">
<h1>This feature coming soon</h1>
</div>
</div>
<div data-role="page" id="AllNews">
<div data-role="content">
<ul data-role="listview">
#for (int i = 0; i < Model.Count; i++ )
{
if (Model[i].type == "Article")
{
<li>
<a href="#Url.Action("NewsItemDetails", "News", new { id = i })">
#if (Model[i].pictureURL != null)
{
<div class="ui-grid-c">
<div class="ui-block-a" style="width:31%;vertical-align:middle">
<img src="#Model[i].pictureURL" style="width:100%;height:auto"/>
</div>
<div class="ui-block-b" style="width:4%; vertical-align:middle"></div>
<div class="ui-block-c" style="width:65%;vertical-align:middle">
<h3 style="font-size:small; white-space:normal">#Model[i].title</h3>
<p><strong>#Model[i].date.ToShortDateString()</strong></p>
</div>
</div>
}
else
{
<h3 style="font-size:small; white-space:normal">#Model[i].title</h3>
<p><strong>#Model[i].date.ToShortDateString()</strong></p>
}
</a>
</li>
}
}
</ul>
</div>
</div>
<div id="PressReleases" data-role="page">
<div data-role"content">
<ul data-role="listview">
#for (int i = 0; i < Model.Count; i++ )
{
if (Model[i].type == "Press Release")
{
<li>
<a href="#Url.Action("NewsItemDetails", "News", new { id = i })">
#if (Model[i].pictureURL != null)
{
<div class="ui-grid-c">
<div class="ui-block-a" style="width:31%;vertical-align:middle">
<img src="#Model[i].pictureURL" style="width:100%;height:auto"/>
</div>
<div class="ui-block-b" style="width:4%; vertical-align:middle"></div>
<div class="ui-block-c" style="width:65%;vertical-align:middle">
<h3 style="font-size:small; white-space:normal">#Model[i].title</h3>
<p><strong>#Model[i].date.ToShortDateString()</strong></p>
</div>
</div>
}
else
{
<h3 style="font-size:small; white-space:normal">#Model[i].title</h3>
<p><strong>#Model[i].date.ToShortDateString()</strong></p>
}
</a>
</li>
}
}
</ul>
</div>
</div>
Your navbar should appear within data-role="page". Within the data-role="page" you should have a data-role="header" and your navbar should go in there if you want it to be in the header of the jqm page.
Alternatively if you don't want to do it that way(which you should do, as its the correct way). You could try catch the onclick event of those links in your navbar yourself and then fire
$.mobile.changePage();
This may work.

Resources