asp.net with underscore templatesettings - asp.net

I suppose there are people who encountered underscore problem, so I found something here:
Using Underscore.js with ASP.NET
and the solution was to add:
_.templateSettings = {interpolate : /\{\{(.+?)\}\}/g, // print value: {{ value_name }}
evaluate : /\{%([\s\S]+?)%\}/g, // excute code: {% code_to_execute %}
escape : /\{%-([\s\S]+?)%\}/g}; // excape HTML: {%- <script> %} prints <script>
to underscore.js
so I opened underscore.js and found the _.templateSettings section, and replaced with the above solution, still with no luck.
Is there anywhere that I'm missing? here's my code looks like:
<table class="table">
<thead>
<tr>
<th></th>
<th>#</th>
<th>Keyword</th>
<th>Corresponding Field</th>
<th>Add</th>
</tr>
</thead>
<tbody>
<% _.each(keywords, function(keyword, key, list) { %>
<tr>
<td><label class="checkbox"><input type="checkbox" /></label></td>
<td><%= key + 1 %></td>
<td><input name="keywords[<%= key %>][keyword]" class="input-medium keyword-name" type="text" value="<%= keyword.name %>" /></td>
<td>
<select class="keyword-field">
<% _.each(fields, function(field, key, list) { %>
<option name="keywords[<%= key %>][field]" value="<%= field.id %>" <% if (keyword.fieldId == field.id) { %>selected<% } %>><%= field.name %></option>
<% }); %>
</select>
</td>
<td class="align-right">Define</td>
</tr>
<% }); %>
</tbody>
</table>

so this is what I end up doing:
<script type="text/javascript">
$(document).ready(function ()
{
_.templateSettings = {
interpolate: /\<\#\=(.+?)\#\>/g,
evaluate: /\<\#(.+?)\#\>/g
};
});
</script>
above code inside html head
and change to <# ... #>
so this is what my code ends up:
<tbody>
<# _.each(keywords, function(keyword, key, list) { #>
<tr>
<td><label class="checkbox"><input type="checkbox" /></label></td>
<td><#= key + 1 #></td>
<td><input name="keywords[<#= key #>][keyword]" class="input-medium keyword-name" type="text" value="<#= keyword.name #>" /></td>
<td>
<select class="keyword-field">
<# _.each(fields, function(field, key, list) { #>
<option name="keywords[<#= key #>][field]" value="<#= field.id #>" <# if (keyword.fieldId == field.id) { #>selected<# } #>><#= field.name #></option>
<# }); #>
</select>
</td>
<td class="align-right">Define</td>
</tr>
<# }); #>
</tbody>

Related

Checkbox not being rendered with correct gentelella css when added via javascript

I'm trying to add some rows data in a datatable, first via Pug and then later on via javascript.
I add the first rows getting data via controller call, and then adding it via pug parse:
<div class="x_content">
<table id="datatable-buttons" class="table table-striped table-bordered bulk_action">
<thead>
<tr>
<th>
<th>Aprovado</th>
</th>
<th>Nome</th>
<th>Email</th>
<th>Data de nascimento</th>
<th>Cidade</th>
<th>Gênero</th>
<th>Escolaridade</th>
<th>Instituição de ensino</th>
<th>Semestre</th>
<th>Token</th>
<th>Selection Status</th>
</tr>
</thead>
<tbody>
for candidate in candidates
- var formatedCandidate = candidateService.formatCandidateForDataTable(candidate, newTrueCheckbox, newFalseCheckbox);
<tr>
<td>
<th>
if formatedCandidate.isCandidateApproved
<input type="checkbox" id="check-all" class="flat" checked>
else
<input type="checkbox" id="check-all" class="flat">
</th>
</td>
<td>
= formatedCandidate.name
</td>
<td>
= formatedCandidate.email
</td>
<td>
= formatedCandidate.bornDate
</td>
<td>
= formatedCandidate.city
</td>
<td>
= formatedCandidate.gender
</td>
<td>
= formatedCandidate.educationLevel
</td>
<td>
= formatedCandidate.educationInstitution
</td>
<td>
= formatedCandidate.educationSemester
</td>
<td>
= formatedCandidate.token
</td>
<td>
= formatedCandidate.selectionStatus
</td>
</tr>
</tbody>
</table>
This way, it manages to render the checkbox with the right style:
Later on, I try to update the rows via a "reload" button, getting data via a get request and then adding rows via javascript:
$.get("candidates/getCandidatesForTable", function(candidatesArray){
candidateTable.clear().draw();
candidatesArray.forEach((candidate, index) => {
debugger;
if (candidate[1]) {
candidate[1] = `<th>
<input type="checkbox" id="check-all" class="flat" checked/>
</th>`;
} else {
candidate[1] = `<th>
<input type="checkbox" id="check-all" class="flat"/>
</th>`;
}
candidateTable.row.add(candidate).draw();
});
});
Although I inserted the HTML code via javascript using the same properties as it was added via pug, the checkbox was rendered different: it is rendered, but the css style is now gone:
How should I add the a checkbox via javascript and still get the correct css styling?

Exception in template helper: Cannot read property 'name' of undefined

I have been struggling with getting a userprofile to display for a specific user for some time now and I have been reasonably successful. I have ht oe problem where I get the error in the heading.
I publish a schools collection like this
Meteor.publish("schoolData", function () {
return Schools.find();
});
My subscription looks like this
Meteor.subscribe('schoolData');
My HTML looks like this
<template name="userProfile">
<title>My Profile</title>
<table>
<tr>
<td>User Name: </td>
<td>{{userName}}</td>
</tr>
<tr>
<td>First Name: </td>
<td>{{firstName}}</td>
</tr>
<tr>
<td>Last Name: </td>
<td>{{lastName}}</td>
</tr>
<tr>
<td>Registered E-mail: </td>
<td>{{email}}</td>
</tr>
<tr>
<td>Contact E-mail: </td>
<td>{{email}}</td>
</tr>
<tr>
<td>Phone Number: </td>
<td>{{phoneNumber}}</td>
</tr>
<tr>
<td>School: </td>
<td>{{schoolName}}</td>
</tr>
<tr>
<td>First year: </td>
<td>{{firstSchoolYear}}</td>
</tr>
<tr>
<td>Last year: </td>
<td>{{lastSchoolYear}}</td>
</tr>
<tr>
<td>Matriculated? </td>
<td>{{matriculated}}</td>
</tr>
<tr>
<td>House Name: </td>
<td>{{houseName}}</td>
</tr>
<tr>
<td>Country living in: </td>
<td>{{country}}</td>
</tr>
<tr>
<td>City living in: </td>
<td>{{cityOfResidence}}</td>
</tr>
<tr>
<td>Industry employed in: </td>
<td>{{emplIndustry}}</td>
</tr>
</table>
</template>
and the javascript looks like this
Template.userProfile.helpers({
email: function() {return Meteor.user().emails[0].address},
userName: function () {return Meteor.user().username},
firstName: function () {return Meteor.user().profile.firstname},
lastName: function () {return Meteor.user().profile.lastname},
phoneNumber: function () {return Meteor.user().profile.phone},
schoolName: function () {return Schools.findOne(Meteor.user().profile.schoolName).name;},
firstSchoolYear: function () {return Meteor.user().profile.firstschoolyear},
lastSchoolYear: function () {return Meteor.user().profile.lastschoolyear},
matriculated: function () {return Meteor.user().profile.matriculated},
houseName: function () {return Meteor.user().profile.housename},
country: function () {return Meteor.user().profile.country},
cityOfResidence: function () {return Meteor.user().profile.cityofresidence},
emplIndustry: function () {return Meteor.user().profile.emplindustry},
signedUp: function () {return Meteor.user().profile.createdAt},
});
I seem to get the Error
Exception in template helper: TypeError: Cannot read property 'name' of undefined
and it mees this is from the Schools collection.
Can someone help me spot my mistake please.
First of all, there is better way to do what you want to achieve- wrap all your html with {{#with user}} tags like this:
<template name="userProfile">
{{#with user}}
<title>My Profile</title>
<table>
<tr>
<td>User Name: </td>
<td>{{userName}}</td>
</tr>
<tr>
<td>First Name: </td>
<td>{{firstName}}</td>
</tr>
<tr>
<td>Last Name: </td>
<td>{{lastName}}</td>
</tr>
<tr>
<td>Registered E-mail: </td>
<td>{{email}}</td>
</tr>
<tr>
<td>Contact E-mail: </td>
<td>{{email}}</td>
</tr>
<tr>
<td>Phone Number: </td>
<td>{{phoneNumber}}</td>
</tr>
<tr>
<td>School: </td>
<td>{{schoolName}}</td>
</tr>
<tr>
<td>First year: </td>
<td>{{firstSchoolYear}}</td>
</tr>
<tr>
<td>Last year: </td>
<td>{{lastSchoolYear}}</td>
</tr>
<tr>
<td>Matriculated? </td>
<td>{{matriculated}}</td>
</tr>
<tr>
<td>House Name: </td>
<td>{{houseName}}</td>
</tr>
<tr>
<td>Country living in: </td>
<td>{{country}}</td>
</tr>
<tr>
<td>City living in: </td>
<td>{{cityOfResidence}}</td>
</tr>
<tr>
<td>Industry employed in: </td>
<td>{{emplIndustry}}</td>
</tr>
</table>
{{/with}}
</template>
And helper like:
user: function(){return Meteor.users.findOne({_id:Meteor.userId()});
Now you can use all data from your user collection in html without helpers
And to your question - you made your query wrong, it should look like this:
schoolName: function () {
return Schools.findOne({name:Meteor.user().profile.schoolName}).name;
},
I assumed you want to check school by name, if you have _id of it in profile.schoolName change name with _id

Meteor Template events, Showing error "Template not define"

I have code like following:
in test.html
<template name="main">
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<td>Name</td>
<td>City</td>
<td>Email</td>
</tr>
</thead>
<tbody>
{{#each users}}
<tr>
<td>{{names}}</td>
<td>{{city}}</td>
<td>{{email}}</td>
</tr>
{{/each}}
<tr>
<td><input type="text" name="names" id="names" value=""></td>
<td><input type="text" name="city" id="city" value=""></td>
<td><input type="text" name="email" id="email" value=""></td>
</tr>
</tbody>
</table>
<button class="btn" id="add">Add</button>
</template>
in test.js
UserInfo = new Meteor.Collection('users');
if (Meteor.isClient) {
Template.main.users=function() {
return UserInfo.find();
}
}
Template.main.events({
'click #add': function () {
var names = $('#names').val();
var city = $('#city').val();
var email = $('#email').val();
UserInfo.insert({names:names,city:city,email:email});
}
});
After clicking on add button i want to take input data(name, location and email) and insert data in to the table but it is showing some error like "template not define".
You should move the Template code inside client block and also creating individual helpers is deprecated. Use helpers block instead.
if (Meteor.isClient) {
Template.main.helpers({
users: function() {
return UserInfo.find();
}
});
Template.main.events({
'click #add': function () {
var names = $('#names').val();
var city = $('#city').val();
var email = $('#email').val();
UserInfo.insert({names:names,city:city,email:email});
};
});
}

TypeError (0x800a01a8): Object required: 'Document'

i have a classic asp page with inside the following vbscript
but it say that the Document object dose not exist why??
TypeError (0x800a01a8): Object required: 'Document'
the vbscript code:
<script language="vbscript" RUNAT="Server">
Function getDescriptionEstProc()
Dim CONNECTSTRING, QUALIFIER, QueryDescEstProc, dbConnect, res,output, param
CONNECTSTRING = Session("CONNECTSTRING")
QUALIFIER = Session("QUALIFIER")
param = PageParams1.UIDMeterHistory
QueryDescEstProc = "select e.description from meterhistory mh, meterread m, estimationprocess e where m.uidestproc = e.uidestproc and m.uidmeter = mh.uidmeter and mh.uidmeterhistory = '"& "0100001" &"'"
Set dbConnect = Server.CreateObject("ADODB.Connection")
Set rsWQType = Server.CreateObject("ADODB.Recordset")
dbConnect.Open CONNECTSTRING
rsWQType.Open QueryDescEstProc, dbConnect
res = ""
Do While Not rsWQType.EOF
res = res & rsWQType("description") & ","
Loop
Dim TheForm
Set TheForm = Document.forms("Form1")
TheForm.hiddenString.Value = res
Response.Write res & " - hello"
getDescriptionEstProc = res
End Function
</script>
(there is no aspx file)
the .asp file:
<form name="Form1" method="post" onkeypress="if (event.keyCode==13) {this.submit();event.returnValue=false;} else event.returnValue=true;">
<input class="lookup" type=hidden name="Id" value="<%=PageParams1.Id%>">
<input type=hidden name="SessionId" value="<%=PageParams1.SessionId%>">
<input type=hidden name="Command" value="">
<input type=hidden name="AccountID" value="<%=PageParams1.AccountID%>">
<input type=hidden name="UIDFACILITY" value="<%=PageParams1.UIDFACILITY%>">
<input type=hidden name="FACILITYID" value="<%=PageParams1.FACILITYID%>">
<input type=hidden name="METERID" value="<%=PageParams1.METERID%>">
<input type=hidden name="UIDMETER" value="<%=PageParams1.UIDMETER%>">
<input type=hidden name="UIDMeterHistory" value="<%=PageParams1.UIDMeterHistory%>">
<input type=hidden name="CustomerName" value="<%=PageParams1.CustomerName%>">
<input type=hidden name="CustomerId" value="<%=PageParams1.CustomerId%>">
<input type=hidden name="EntityParam" value="<%=PageParams1.EntityParam%>">
<input type=hidden name="SORT_BY" value="<%=PageParams1.SORT_BY%>">
<input type=hidden name="SORT_ORDER" value="<%=PageParams1.SORT_ORDER%>">
<input type=hidden name="Mode" value="<%=PageParams1.Mode%>">
<table class="SnapIn" cellpadding="0" cellspacing="0" border=0><tr class="ToolsTabs">
<td class="Title"><nobr><%=Proxy1.i18n.FM("MeterHistory")%></nobr></td>
<td class="ToolsLeft">
<b><%=Proxy1.i18n.FM("ID")%></b> <%=meterId %>
<%if (PageParams1.Mode == "ServicePoint") {%>
| <a href="../../ccs/MainWebPart.aspx?Mode=
<%=PageParams1.Mode%>&SessionId=<%=PageParams1.SessionId%>&Uid=
<%=Proxy1.Session.GetPropertyValue("SERVICEPOINT_UID")%>">
<%=Proxy1.i18n.FM("ServicePointSummary")%></a>
<% } else if (PageParams1.Mode == "MarketParticipant") { %>
| <a href="../../ccs/MainWebPart.aspx?Mode=
<%=PageParams1.Mode%>&SessionId=<%=PageParams1.SessionId%>&Uid=
<%=Proxy1.Session.GetPropertyValue("MARKETPARTICIPANT_UID")%>">
<%=Proxy1.i18n.FM("MarketParticipantSummary")%></a>
<% } %>
</td>
<td class="ToolsRight"><nobr>
<%if (PageParams1.AccountID) {%>
<b><%=Proxy1.i18n.FM("AccountID")%></b>
<a class="Link" onclick='window.navigate("../viewaccount/Meters.asp?Id=<%= escape(PageParams1.AccountID)%>&SessionId=<%=PageParams1.SessionId%>")'><u><%=PageParams1.AccountID %></u></a>
<%} if (PageParams1.CustomerId) {%>
<b><%=Proxy1.i18n.FM("CustomerID")%></b>
<a class='Link' onclick='navigate("../../ccs/MainWebPart.aspx?Id=<%=escape(PageParams1.CustomerId)%>&SessionId=<%=PageParams1.SessionId%>"+"&Mode=Customer")'>
<%=PageParams1.CustomerId%>
</a>
<%} if (PageParams1.UIDFACILITY) {%>
<b><%=Proxy1.i18n.FM("FacilityID")%></b>
<a class=Link onclick='navigate("../cust_facility/Basics.asp?UIDFACILITY=<%=PageParams1.UIDFACILITY%>&SessionId=<%=PageParams1.SessionId%>&X_ROWPERPAGE=50")'>
<%=PageParams1.FACILITYID%>
</a>
<%}%>
</nobr></td>
</tr><tr>
<td class="TabBox" colspan="3"><%= RenderTabs("MeterRead") %></td>
</tr><tr>
<td class="Body" colspan="3">
<% if (OperationError) ReportError(OperationError)%>
<%if (PageParams1.Command=='Edit') { %>
<table width=100%><tr><td class=LinkBox>
<%if (Proxy1.Allow("//ACCTMGT/ACCTCOMP/ACCTMET/#UPDATE")) {%>
<%=Proxy1.i18n.FM("Save")%> |
<%}%>
<%if (PageParams1.EntityParam && Proxy1.Allow("//ACCTMGT/ACCTCOMP/ACCTMET/#REMOVE") ) { %><%=Proxy1.i18n.FM("Delete")%> |<% } %>
<%=Proxy1.i18n.FM("Cancel")%>
</td></tr></table>
<%} else%>
<%=tMeterHistoryTable %>
<%if (PageParams1.Command != 'Edit') { %>
<table style="width: expression(Math.max(document.body.offsetWidth-55, 540))">
<tr>
<td align=left>
<%
if (Proxy1.Allow("//FACILITY/ADD"))
{
%>
<a href="javascript: Edit()" ><%=Proxy1.i18n.FM("Add")%></a>
<%
}
if (Proxy1.Allow("//FACILITY/REEST_ACTION/#REESTIMATE")) { %>
Ristima
<%
}
if (Proxy1.Allow("//FACILITY/REEST_ACTION_2")) { %>
Ristima lettura conferimento
<% }
if (Proxy1.Allow("//FACILITY/REEST_ACTION/#DISCHARGE")) { %>
Scarta
<% } %>
</td>
<!--Indicazione righe e pagina-->
<td align=right>
<%= Paginator_b(PageParams1.ROWPERPAGE, PageParams1.PAGENUMBER) %>
</td>
</tr>
</table>
<%
}
%>
<div class="mAppScroll" style="height:100% width:100%"><% =tTable %></div>
<tr>
<td>
<!--Cannata Alberto - modifica del 09/10/2006: aggiorniamo i campi LSUSER e LSTIME della METERHISTORY.-->
<input type="hidden" name = "OLD_STATUS" value = "<%=oldstatus_str%>">
<input type="hidden" name = "X_LSUSER" value = "<%=username_web.toUpperCase()%>">
<input type="hidden" name = "X_LSTIME" value = "<%=data_modifica%>">
</td>
</tr>
</td>
</tr>
</table><!-- /SnapIn -->
<input type="hidden" id="hiddString" name="hiddenString" value="">
<%
getDescriptionEstProc();
%>
<SCRIPT language="javascript">
appendColumn();
</SCRIPT>
Document.Forms is not used in server-side ASP, it's used in client-side code such as Javascript and VBScript. If you are trying to post data with your form, look into using Request["fieldname"] to get the values you need.
It looks like you're just trying to set the value of the hidden field?
Since the function returns the value you want (res), just do this:
<input type="hidden" id="hiddString" name="hiddenString" value="<%=getDescriptionEstProc()%>">
Hope this helps.
Good luck.

Can't Get ASP.NET MVC Form To Post

I am having problems getting my form to Post to my Save method in a controller. I am new to MVC, and have followed several examples to try to get this to work. Here is my html markup:
<form action="Edit/Save" method="post">
<fieldset>
<legend>Personal Information</legend>
<table class="editGrid">
<tr>
<td><label for="txtFirstName">First Name:</label></td>
<td><input type="text" id="txtFirstName" value="<%=user.FirstName %>" name="FirstName" /></td>
</tr>
<tr>
<td><label for="txtLastName">Last Name:</label></td>
<td><input type="text" id="txtLastName" value="<%=user.LastName %>" name="LastName" /></td>
</tr>
<tr>
<td><label for="txtNtLogin">NT Login:</label></td>
<td><input type="text" id="txtNtLogin" value="<%=user.NtLogin %>" name="NtLogin" /></td>
</tr>
<tr>
<td><label for="txtHireDate">Hire Date:</label></td>
<td><input type="text" id="txtHireDate" value="<%=string.Format("{0:d}",user.HireDate) %>" name="HireDate" /></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Job Information</legend>
<table class="editGrid">
<tr>
<td><label for="CostCenters">Cost Center:</label></td>
<td><%=Html.DropDownList("CostCenters")%></td>
</tr>
<tr>
<td><label for="Managers">Manager:</label></td>
<td><%=Html.DropDownList("Managers")%></td>
</tr>
<tr>
<td><label for="Responsibilities">Responsibility:</label></td>
<td><%=Html.DropDownList("Responsibilities")%></td>
</tr>
<tr>
<td><label for="Departments">Department:</label></td>
<td><%=Html.DropDownList("Departments")%></td>
</tr>
<tr>
<td><label for="Active">Active:</label></td>
<td><%=Html.CheckBox("Active",user.Active) %></td>
</tr>
<tr>
<td><label for="txtHireDate">Hire Date:</label></td>
<td><%=Html.TextBox("txtHireDate",string.Format("{0:d}",user.HireDate)) %></td>
</tr>
<tr>
<td><label for="txtReleaseDate">Release Date:</label></td>
<td><%=Html.TextBox("txtReleaseDate",string.Format("{0:d}",user.ReleaseDate)) %></td>
</tr>
</table>
</fieldset>
<input type="submit" value="Save Changes" />
</form>
This form routes to a Save method in my EditController. Here is the code for my EditController's Save method:
public class EditController : Controller
{
public ActionResult Save()
{
//Save code goes here
}
I have tried using the html form tag, and also the Html helper code:
using (Html.BeginForm("Save", "Edit"))
Here is the entry from my RegisterRoutes method in the Global.asax file:
routes.MapRoute("EditSave", "{controller}/Save",
new { controller = "Edit", action = "Save" });
No matter what I do, the submit button does not trigger the Save method. Yet, if I manually key in the Url, The code breaks right into the Save method.
Edit:
Per Craig Stuntz's comment, I checked the source of the page. The page actually contains 2 forms, although only 1 is coded on the page by myself: Here is the HTML that appears prior to my form tag:
<form name="aspnetForm" method="post" action="44" id="aspnetForm">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNjM3OTAyNTUzZGQrHhVn9+t78aHxN0vHvKUJ8DQWlQ==" />
</div>
<div id="nav">
<span id="navLinks">
Placeholder Link
</span>
<span id="userName">
<span id="ctl00_lblUserName" class="UserName">Welcome, Test User</span>
</span>
</div>
<div id="Content">
<div id="formContainer">
<form action="Edit/Save" method="post">
I didn't think MVC generated viewstate or additional form tags. I am pulling data and populating it into this form using another method from the same controller. Am I doing something wrong here?
Ok, got the answer. And thanks Craig for having me look at the HTML again! My master page had generated a form tag in it without my knowing it, so I essentially had nested forms on the same page. After I removed the form from the Master Page, everything worked perfectly.

Resources