Why does the clone remove method doesn't work after the function was altered? - jquery-ui

I have been trying to delete specific clone data using JQuery -UI. i had to change my functions recently since then the remove button doesn't work. Please help me find my error.
My whole function that includes, Multidimensional Arrays along with form cloning! check out my remove function which i think has no problem in it.
$(function() {
var questionHolder = $('.question').clone(true);
$("#addQuestion").on('click', function(e) {
e.preventDefault();
var str = $("p.number:last").text(),
newValue = parseInt(str, 10) + 1;
var newQ = questionHolder.clone();
newQ.find('input, textarea')
.each(function() {
this.name = this.name.replace(/\[(\d+)\]/, '[' + newValue + ']');
})
.end()
.find('.number')
.html(newValue)
.end()
.appendTo('#questioncontainer')
.after('<br><button class="addQuestion_delete btn btn-danger" type="button">Remove Parent Clone</button><br>');
$(".addQuestion_delete").click(function(e) {
$(this).closest("#questioncontainer").remove();
e.preventDefault();
});
});
$('body').on('click', '.addAnswer', function(e) {
e.preventDefault();
var group = $(this).parent();
parent = $(this).parent().parent();
group.find(".answer:last")
.clone(true)
.find('input, textarea')
.each(function() {
this.name = this.name.replace(/\[(\d+)\]$/,
function(str, p1) {
return '[' + (parseInt(p1, 10) + 1) + ']';
});
})
.end()
.appendTo(
group.find('.answerContainer'))
.after('<button class="addAnswer_delete btn btn-danger" type="button"><i class="fa fa-minus"></i>Remove Child clone</button><br><br><br>');
$(".addAnswer_delete").click(function(e) {
$(this).closest(".answerContainer").remove();
e.preventDefault();
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- parent container -->
<div id="questioncontainer">
<!-- parent that clones -->
<div style="border:1px solid black; width:400px; padding:20px; margin-bottom:10px;" class="question border p-5 mt-3 shadow">
<!-- clone items inputs/textareas/files -->
<div class="row">
<div class="col-lg-6">
<!-- Educational Institute -->
<input oninput="checkCompany()" id="company" name="employer[1]" type="text" class="input-form track track_exp_qua" data-score=20>
<span class="bar"></span>
<label class="input-label"> Company <span id="text" class="required"> </span></label>
<!-- Educational Institute -->
<p class="validate text-danger pt-2" id="company_error"></p>
</div>
<div class="col-lg-6">
<!-- Job title -->
<input oninput="checkJobTitle()" id="job_title" name="job_title[1]" type="text" class="input-form track track_exp_qua" data-score=10>
<span class="bar"></span>
<label class="input-label"> Job Title <span id="text" class="required"> </span></label>
<!-- Job title -->
<p class="validate text-danger pt-2" id="job_title_error"></p>
</div>
</div>
<div class="justify-content-center pb-4">
<h4>Below is the child clone</h4>
</div>
<!-- child container -->
<div style="border:1px solid red; padding:20px;" class="answerContainer">
<div class="answer">
<div class="row">
<!-- best project url -->
<div class="col-lg-6">
<input name="best_project[1][1]" type="text" class="input-form track track_exp_qua" data-score=10>
<span class="bar"></span>
<label class="input-label">Best Project<small style="color:#FFBF00;"> (URL's Only) </small> <span id="text" class="optional"> </span></label>
</div>
<!-- best project url -->
</div>
<br>
</div>
</div>
<!-- clone items inputs/textareas/files end-->
<br>
<button class="addAnswer btn btn-info" href="#"><i class="fa fa-plus"></i> Add Child</button>
</div>
<!-- parent that clones end-->
</div>
<!-- parent container end -->
<br>
<button id="addQuestion" class="btn btn-success" href="#"> <i class="fa fa-plus"></i> Add Parent </button>

Some of your objects were too ambigous, so things were not going to work as you expected.
Consider the following example.
$(function() {
function updateName(i, n) {
i = $(i);
var o = i.attr("name");
if (n != undefined) {
i.attr("name", o.replace(/\[(\d+)\]/, '[' + n + ']'));
} else {
i.attr("name", o.replace(/\[(\d+)\]$/,
function(str, p1) {
return '[' + (parseInt(p1, 10) + 1) + ']';
}));
}
return true;
}
function makeDel(cnt, pClass, tObj) {
return $("<button>", {
class: pClass + " btn btn-danger",
type: "button"
}).html(cnt).insertAfter(tObj);
}
function addQuestion(event) {
var self = $(event.target);
event.preventDefault();
var newValue = $(".question").length + 1;
var newQ = $(".question").eq(0).clone(true);
$("input, textarea", newQ).each(function() {
updateName(this, newValue);
});
newQ.appendTo("#questioncontainer");
var newD = makeDel("Remove Parent Clone", "addQuestion_delete", newQ);
newD.click(function(e) {
e.preventDefault();
newQ.remove();
$(this).remove();
});
}
function addAnswer(event) {
var self = $(event.target);
event.preventDefault();
var group = self.parent().find(".answerContainer");
var newA = $(".answer:last", group).clone(true);
$("input, textarea", newA).each(function() {
updateName(this);
});
newA.appendTo(group);
var newD = makeDel("<i class='fa fa-minus'></i> Remove Child clone", "addAnswer_delete", group);
newD.click(function(e) {
e.preventDefault();
newA.remove();
$(this).remove();
});
}
$("body").on("click", "#addQuestion", addQuestion);
$('body').on('click', '.addAnswer', addAnswer);
});
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- parent container -->
<div id="questioncontainer">
<!-- parent that clones -->
<div style="border:1px solid black; width:400px; padding:20px; margin-bottom:10px;" class="question border p-5 mt-3 shadow">
<!-- clone items inputs/textareas/files -->
<div class="row">
<div class="col-lg-6">
<!-- Educational Institute -->
<input oninput="checkCompany()" id="company" name="employer[1]" type="text" class="input-form track track_exp_qua" data-score=20>
<span class="bar"></span>
<label class="input-label"> Company <span id="text" class="required"> </span></label>
<!-- Educational Institute -->
<p class="validate text-danger pt-2" id="company_error"></p>
</div>
<div class="col-lg-6">
<!-- Job title -->
<input oninput="checkJobTitle()" id="job_title" name="job_title[1]" type="text" class="input-form track track_exp_qua" data-score=10>
<span class="bar"></span>
<label class="input-label"> Job Title <span id="text" class="required"> </span></label>
<!-- Job title -->
<p class="validate text-danger pt-2" id="job_title_error"></p>
</div>
</div>
<div class="justify-content-center pb-4">
<h4>Below is the child clone</h4>
</div>
<!-- child container -->
<div style="border:1px solid red; padding:20px;" class="answerContainer">
<div class="answer">
<div class="row">
<!-- best project url -->
<div class="col-lg-6">
<input name="best_project[1][1]" type="text" class="input-form track track_exp_qua" data-score=10>
<span class="bar"></span>
<label class="input-label">Best Project<small style="color:#FFBF00;"> (URL's Only) </small> <span id="text" class="optional"> </span></label>
</div>
<!-- best project url -->
</div>
<br>
</div>
</div>
<!-- clone items inputs/textareas/files end-->
<br>
<button class="addAnswer btn btn-info" href="#"><i class="fa fa-plus"></i> Add Child</button>
</div>
<!-- parent that clones end-->
</div>
<!-- parent container end -->
<br>
<button id="addQuestion" class="btn btn-success" href="#"> <i class="fa fa-plus"></i> Add Parent </button>
Objects are created and referenced a bit better, so it's easier to manipulate them and remove them as needed. Anytime you are doing the same thing multiple times, you could consider creating a function for it.

Related

MVC Project memory leaking, how to fix it?

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>
}

Bootstrap 3 - Row Fixed Issue

I am strugling with Bootstrap 3 grid system.
Let me explain what I have implemented, what I need and what I did (fail attempt) to achieve.
This is the Layout (HTML | Razor) of the image. For you to have a live version of this This is the site link to this screen so you can see it and play.
<div class="row">
<div class="col-xs-12 col-md-6 nopadding">
<div id="showcaseSection" class="showcaseSection superVideo">
<ul class="media-list" id="showcaseMedia" itemscope itemtype="http://schema.org/UserComments"></ul>
</div>
<div class="hidden-xs">
<div class="col-xs-6 nopadding">
<p class="text-center no-margin" style="margin-top: 15px;">
<span>Equipo: #Model.Team1Name (<span id="team1Total">0</span>)</span>
</p>
<ul class="media-list team1ListShowCase" id="#Model.Team1Id" data-img="#Url.Action("GetLinkToImageTeam", "Home", new {Id = Model.Team1Id})" data-media="media-left" data-team="#Model.Team1Name" data-class="team1"></ul>
</div>
<div class="col-xs-6 nopadding">
<p class="text-center no-margin" style="margin-top: 15px;">
<span>Equipo: #Model.Team2Name (<span id="team2Total">0</span>)</span>
</p>
<ul class="media-list team2ListShowCase" id="#Model.Team2Id" data-img="#Url.Action("GetLinkToImageTeam", "Home", new {Id = Model.Team2Id})" data-media="media-right" data-team="#Model.Team2Name" data-class="team2"></ul>
</div>
</div>
</div>
<div class="col-xs-12 col-md-6">
<div class="col-xs-12 col-md-6 nopadding">
<div id="chatcontainer">
<ul class="media-list" id="chatbody" itemscope itemtype="http://schema.org/UserComments"></ul>
<div id="chatOptions" class="collapse">
<p class="text-center">#Model.Title</p>
<button id="exitroom" class="btn btn-danger" title="Salir" disabled="disabled">
<span class="glyphicon glyphicon-log-out"></span> #Resources.Salir
</button>
<span>
<input type="checkbox" id="isAutoscroll" name="my-checkbox" checked>
<label>Actualizar Mensajes</label>
</span>
</div>
</div>
#if (!Model.IsReadOnly)
{
<div class="input-group">
<input type="hidden" style="display: none" class="form-control" aria-required="false" readonly id="inresponseto">
<textarea type="text" rows="2" class="form-control" required="required" aria-required="true" maxlength="500" placeholder="Comentario..." disabled="disabled" id="responseText"></textarea>
<input type="text" class="form-control" style="height: 25px;" aria-required="false" readonly id="inresponsetomessage">
<span class="input-group-btn">
<button id="sendresponse" type="button" title="Enviar" class="btn btn-primary" disabled="disabled">
<span class="glyphicon glyphicon-send"></span>
</button>
<button class="btn btn-info" data-toggle="collapse" title="Opciones" data-target="#chatOptions">
<span class="fa fa-cogs"></span>
</button>
</span>
</div>
}
</div>
</div>
As you can see everything is in one row.
I want to have the Video Section fixed on top and the TEXT AREA to comment fixed BOTTOM when on XS (viewports).
I tried adding this to the row, but I fix the video but I cannot see the TEXT AREA
.fixed2 {
position: fixed;
z-index: 10;
width: 100%;}
I don't know what else to do to show fixed top (video) and botton fixed (Chat Textbox) and scrollable comments in the middle when in XS.
Any help is welcome.
Override the height for #chatcontainer for tablet/mobile will fix the issue. Example:
#media(max-width: 767px) {
#chatcontainer{
height: calc(50vh - 80px);
}
}

Open the Same Page as Both Normal and Bootstrap Pop-Up

As you can see in the picture below I have a form for adding notes and a form for editing notes on my page. What I want to do is: When I click edit button ("Düzenle" in my page), I want to open the window on the right as a pop-up.
The part codes on the left side of the picture ProjeListPartial.cshtml:
#model List<tbl_Not>
#if (Model.Any())
{
<div class="col-md-12 col-sm-12">
<div class="portlet light bordered">
<div class="portlet-title">
<div class="caption caption-md">
<i class="icon-bar-chart font-dark hide"></i>
<span class="caption-subject font-dark bold uppercase"><a>Proje Notları Toplam: #Model.Count() </a></span>
</div>
</div>
<div class="portlet-body">
<div class="scroller" style="height: 338px;" data-always-visible="1" data-rail-visible1="0" data-handle-color="#D7DCE2">
<div class="general-item-list">
#foreach (var item in Model)
{
<div class="item">
<div class="item-head">
<div class="item-details">
<a class="item-name primary-link">#item.Adi</a>
<br />
#if (Fonksiyonlar.KulYetSvys((int)Sabitler.YtkSeviyesi.TamYetki))
{
<span class="item-label">#item.tbl_Kullanici.Adi</span>
}
<span class="item-label">#item.EklenmeTarihi.ToString("dd.MM.yyy")</span>
#if (Fonksiyonlar.KulYetSvys((int)Sabitler.YtkSeviyesi.BirimTamYetki) || Fonksiyonlar.KulYetSvys((int)Sabitler.YtkSeviyesi.TamYetki))
{
<span class="item-status">
<!-- This is my edit code -->
Düzenle
<!-- -->
Sil
</span>
}
</div>
</div>
<div class="item-body"> #item.Icerik </div>
</div>
}
</div>
</div>
</div>
</div>
</div>
<div class="row" style="margin-left: 0px;">
<div class="col-md-12">
<div class="dataTables_paginate paging_bootstrap_number hidden-print" id="sample_3_paginate">
<ul class="pagination" style="visibility: visible;">
#Html.Raw(ViewBag.Sayfalama)
</ul>
</div>
</div>
</div>
}
else
{
<h3>Not Bulunmamaktadır.</h3>
}
The part codes on the right side of the picture Ekle.cshtml:
#model tbl_Not
#{
ViewBag.Title = "Not";
bool IsProjeNotu = Model.ProjeID > 0 ? true : false;
if (IsProjeNotu)
{
Layout = null;
}
}
<div class="portlet box blue">
<div class="portlet-title">
<div class="caption">
<i class="fa fa-file-o"></i>Not Ekle/Düzenle
</div>
<div class="tools">
</div>
</div>
<div class="portlet-body #(IsProjeNotu?"portlet-collapsed":"")">
<form method="post" role="form" action="#Url.Action("Ekle", "Not", new { ProjeID = Model.ProjeID, BirimID = Model.BirimID, IsProjeNotu = IsProjeNotu })">
<input type="hidden" name="ID" value="#Model.ID" />
<div class="form-body">
#if (!IsProjeNotu)
{
<div class="col-lg-6 formbox pl">
<span>Birim Adı:</span>
<select name="BirimID" id="Birim" class="form-control">
#Html.Raw(ViewBag.Birim)
</select>
</div>
<div class="col-lg-6 pl pr formbox" onchange="return IlGetir();">
<span>Proje Adı:</span>
<select name="ProjeID" id="Projeler" class="form-control"></select>
</div>
}
<div class="col-md-6 pl formbox">
<span>İl/İller:</span>
<select multiple id="Iller" class="form-control">
#foreach (tbl_Il item in ViewBag.Iller)
{
<option value="#item.ID">#item.Adi</option>
}
</select>
<button id="SolaYolla" type="button" class="btn blue btn-sm" data-style="slide-up" data-spinner-color="#333">
<i class="fa fa-plus"></i> Ekle
</button>
</div>
<div class="col-md-6 formbox pr">
<span>İl Çıkar</span>
<select multiple id="SecilenIller" name="IlID" class="form-control">
#foreach (tbl_NotIlIliski item in Model.tbl_NotIlIliski.ToList())
{
<option value="#item.IlID">#item.tbl_Il.Adi</option>
}
</select>
<button id="SagaYolla" type="button" class="btn blue btn-sm" data-style="slide-up" data-spinner-color="#333">
<i class="fa fa-close"></i> Çıkar
</button>
</div>
<div class="col-md-12 formbox pr pl">
<span>Başlık:</span>
<input type="text" maxlength="250" class="form-control" style="width: 230px;" value="#Model.Adi" name="Adi" />
</div>
<div class="col-md-12 formbox pr pl">
<span>İçerik:</span>
<textarea class="mceEditor" style="width: 230px;" name="Icerik">#Model.Icerik</textarea>
</div>
</div>
<div class="col-md-12 formbox pr pl">
<span>Not Durumu:</span>
#foreach (var item in Sabitler.NotDurum)
{
<label class="mt-radio mt-radio-outline" style="margin-left: 15px;">
#item.Adi
<input #( Model.DurumID == 0 ? (item.ID == 1 ? "checked='checked'" : "") : (item.ID == Model.DurumID ? "checked='checked'" : "") ) type="radio" value="#item.ID" name="DurumID" />
<span></span>
</label>
}
</div>
<input type="submit" class="btn blue" id="Kaydet" onclick="$('#SecilenIller option').prop('selected', true);" value="Kaydet" />
</form>
</div>
When I click edit button (Düzenle), this is how a screen comes out:

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.");
}
}

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...

Resources