EJS syntax error while compiling ejs code - ejs

SyntaxError: Unexpected token ')' in C:\Users\hp\short.nner\views\index.ejs while compiling ejs
If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint
at new AsyncFunction (<anonymous>)
at Template.compile (C:\Users\hp\short.nner\node_modules\ejs\lib\ejs.js:661:12)
at Object.compile (C:\Users\hp\short.nner\node_modules\ejs\lib\ejs.js:396:16)
at handleCache (C:\Users\hp\short.nner\node_modules\ejs\lib\ejs.js:233:18)
at tryHandleCache (C:\Users\hp\short.nner\node_modules\ejs\lib\ejs.js:272:16)
at View.exports.renderFile [as engine] (C:\Users\hp\short.nner\node_modules\ejs\lib\ejs.js:489:10)
at View.render (C:\Users\hp\short.nner\node_modules\express\lib\view.js:135:8)
at tryRender (C:\Users\hp\short.nner\node_modules\express\lib\application.js:640:10)
at Function.render (C:\Users\hp\short.nner\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (C:\Users\hp\short.nner\node_modules\express\lib\response.js:1012:7)
at C:\Users\hp\short.nner\server.js:49:17
at processTicksAndRejections (node:internal/process/task_queues:93:5)
Here's my code:
<%=Url.forEach(shortUrl => { %>
<tr>
<td>
<a href="<%= shortUrl.full %>">
<%= shortUrl.full %>
</a>
</td>
<td>
<a href="<%= shortUrl.short %>">localhost:3000/<%= shortUrl.short %></a
>
</td>
<td><%= shortUrl.clicks %></td>
<td><%= shortUrl.GivenEmail %>
</tr>
<% }) %>
I really don't know why I am getting this error please help.
I did give the Url as an option to my ejs but I get this strange error on running it.

I wasn't able to fully test your code yesterday because I was on mobile.
The problem is actually coming from the = in the beginning of <%=Url.forEach(shortUrl =>. Just remove it like this should work:
<% Url.forEach(shortUrl => { %>
<tr>
<td>
<a href="<%= shortUrl.full %>">
<%= shortUrl.full %>
</a>
</td>
<td>
<a href="<%= shortUrl.short %>">localhost:3000/<%= shortUrl.short %></a
>
</td>
<td><%= shortUrl.clicks %></td>
<td><%= shortUrl.GivenEmail %>
</tr>
<% }) %>
That should dismiss the error.

Related

Passing data from table to Modal Table

I have two tables for my inventory first is the Item List then the Item Info
I bind the Item List to a HTML Table the add a button for each row the purpose of the button is to show the Item Info or table via modal
I have already done the table and modal design but i cant get or pass the Item ID for my Item List to my modal
can anyone help me i'm kind a new in HTML (noob hir :3)
<thead>
<tr>
<th class="text-center">Item ID</th>
<th class="text-center">Particular</th>
</tr>
</thead>
<tbody class="searchable">
<% List<Inventory.MODEL.adminView>x = new List
<Inventory.MODEL.adminView>(); Inventory.BAL.ItemBAL z = new Inventory.BAL.ItemBAL(); x = z.getAdminView().ToList(); foreach (var item in x) {%>
<tr>
<td>
<%=i tem.ID %>
</td>
<td>
<%=i tem.Particulars %>
</td>
<%}%>
<td class="text-center">
<span class='glyphicon glyphicon-info-sign'></span>
</td>
</tr>
<%} %>
</tbody>
</table>
</div>
</div>
<div id="Modal" class="modal fade">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Item Inventory</h4>
</div>
<div class="modal-body">
<table class="table table-hover table-bordered">
<thead>
<tr>
<th class="text-center">Item ID</th>
<th class="text-center">Total Quantity</th>
</tr>
</thead>
<tbody>
<% iteminvents(); %>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
that's my code, anyone can advice or can help me ?
Pass this in myFunction() as argument , As myFunction(this)
and inside function you can get ItemId as below. I have used jquery here.
function myFunction(sender)
{
var CurrentRow=$(sender).closest("tr");
var ItemId=$("td:eq(0)",$(CurrentRow)).html(); // Can Trim also if needed
}

CanJS EJS table - rows appearing above the table

I am new to CanJS and was trying to learn via tutorials.. Once place where I got stuck was when I converted the todo tutorial code to use table instead of UL/LI combination.
May be I am making some very small mistake.. but could not find out the same for last 3 days.. Can someone help out?
The jsFiddle for the short version of todo tutorial (which now uses tables) is here where you can see the problems.
The crux of the code from ejs is here..
<script type='text/ejs' id='todosEjs'>
<table border="1">
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>status</th>
</tr>
</thead>
<tbody>
<!-- bind to changes in the todo list -->
<% this.each(function( todo ) { %>
<!-- add the todo to the element's data -->
<tr <%= (el) -> el.data('todo',todo) %>>
<td>
<input type="checkbox" <%= todo.attr('complete') ? 'checked' : '' %>>
</td>
<td><%= todo.attr('name') %></td>
<td><%= todo.attr('id') %></td>
</tr>
<% }) %>
</tbody>
</table>
</script>
Looking forward towards helping hands :-)
UPDATE: This was the result of a bug which is now fixed
It looks as if the comments are the problem here. Removing them makes it work, see the updated Fiddle:
<table border="1">
<tr>
<th>id</th>
<th>name</th>
<th>status</th>
</tr>
<% this.each(function( todo ) { %>
<tr <%= (el) -> el.data('todo',todo) %>>
<td>
<input type="checkbox" <%= todo.attr('complete') ? 'checked' : '' %>>
</td>
<td><%= todo.attr('name') %></td>
<td><%= todo.attr('id') %></td>
</tr>
<% }) %>

Handling Multiple Submit Buttons

I Have a Strongly typed user control which i use for Searching a certain list of objects.
the following code shows the user control,
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<PeercoreCRM.ViewModels.CustomerFilterViewModel>" %>
<div style="width: 100%;vertical-align:top;background-color:White">
<fieldset>
<legend>Criteria</legend>
<table cellspacing="0">
<tr>
<td style="width: 100px">
<div class="editor-label">
<%: Html.LabelFor(m => m.LeadName) %>
</div>
</td>
<td>
<div class="editor-field">
<%: Html.TextBoxFor(m => m.LeadName) %>
</div>
</td>
</tr>
<tr>
<td style="width: 60px">
<div class="editor-label">
<%: Html.LabelFor(m => m.CustomerCode) %>
</div>
</td>
<td>
<div class="editor-field">
<%: Html.TextBoxFor(m => m.CustomerCode)%>
</div>
</td>
</tr>
<tr>
<td>
<input type="submit" name="btnSearch" value="Search" />
<input type="submit" name="btnCancel" value="Cancel" />
</td>
<td>
</td>
</tr>
</table>
</fieldset>
</div>
In the View, I show this user control conditionally using the following code snippet,
<% using (Html.BeginForm("CustomerList", "Customer", new { isFiltered = Model.FilterViewModel.IsFiltered }, FormMethod.Post))
{
%>
<% if (Model.FilterViewModel.IsVisible) Html.RenderPartial("ListFilterUserControl", Model.FilterViewModel); %>
<% } %>
I have put the Form in the rendering page as this control is used in other views and thereby calling other action methods in different controllers.
I have the following method signature in my controller action method,
[HttpPost]
public ActionResult CustomerList(CustomerFilterViewModel filterModel)
{
bool filtered = filterModel.IsDirty? FilterCustomers(filterModel):false;
Session["CurrentPageNumber"] = null;
return RedirectToAction("CustomerList", new { isFiltered = filtered || filterModel.IsFiltered });
}
My problem is, with this implementation, how can i separately identify which button is clicked ("Search" or "Cancel") and to write the code depending on that.
To identify the button that has been passed in, you can group your buttons by adding a name attribute to them:
<input name="button" type="submit" value="Search" />
<input name="button" type="submit" value="Cancel" />
then, add a variable that is passed into your post method with the same name of the buttons (in this case "button") like this:
[HttpPost]
public ActionResult CustomerList(string button, CustomerFilterViewModel filterModel)
{
if(button.Equals("Search"))
{
bool filtered = filterModel.IsDirty? FilterCustomers(filterModel):false;
Session["CurrentPageNumber"] = null;
return RedirectToAction("CustomerList", new { isFiltered = filtered || filterModel.IsFiltered });
} else {
if(button.Equals("Cancel")) {
//perform cancel
}
}
}

How can I strongly-type in what my View inherits from?

CS0234: The type or namespace name 'Helpers' does not exist in the namespace 'UTEPSA' (are you missing an assembly reference?)
Here is the view code that's trying to inherit:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<UTEPSA.Helpers.PaginatedList<Area>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Index</h2>
<table>
<tr>
<th></th>
<th>
ID
</th>
<th>
IDJefe
</th>
<th>
Nombre
</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%: Html.ActionLink("Edit", "Edit", new { id=item.ID }) %> |
<%: Html.ActionLink("Details", "Details", new { id=item.ID })%> |
<%: Html.ActionLink("Delete", "Delete", new { id=item.ID })%>
</td>
<td>
<%: item.ID %>
</td>
<td>
<%: item.IDJefe %>
</td>
<td>
<%: item.Nombre %>
</td>
</tr>
<% } %>
</table>
<p>
<%: Html.ActionLink("Create New", "Create") %>
</p>
</asp:Content>
And a screenshot of my solution:
How can I correctly reference my PaginatedList? Since the view is inheriting from my thing I want, I'd expect to have strongly typed Model to work with. But intellisense isn't working so somethings wrong.
You must add the assembly to both the Project Reference list as well as the <system.web><compilation><assemblies> section of web.config.

Renderpartial or renderaction

have an action that generates active vacancies. The code is below;
public ViewResult OpenVacancies()
{
var openvacancies = db.GetActiveVacancies();
return View(openvacancies);
}
I want to use this list on several pages so i guess the best thing to use is html.renderaction (please correct me if i am wrong here).
Please note that the view and .ascx control are in an Area.
I then created a view by right clicking inside the action and create a .ascx and a strongly typed view of Vacancy. I chose a view content of "List".
I then added this line to the required page;
Please note that the view and .ascx control are in an Area.
The error i got is;
The type or namespace name 'Vacancy' could not be found (are you missing a using directive or an assembly reference?)
the .ascx code is below;
>" %>
<table>
<tr>
<th></th>
<th>
VacancyID
</th>
<th>
JobTitle
</th>
<th>
PositionID
</th>
<th>
LocationID
</th>
<th>
JobDescription
</th>
<th>
JobConditions
</th>
<th>
Qualifications
</th>
<th>
RequiredSkills
</th>
<th>
Certifications
</th>
<th>
AdvertDate
</th>
<th>
AdvertExpiryDate
</th>
<th>
Status
</th>
<th>
StaffLevel
</th>
<th>
LineManagerEmail
</th>
<th>
ApprovalFlag
</th>
<th>
RequisitionDate
</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%= Html.ActionLink("Edit", "Edit", new { id=item.VacancyID }) %> |
<%= Html.ActionLink("Details", "Details", new { id=item.VacancyID })%> |
<%= Html.ActionLink("Delete", "Delete", new { id=item.VacancyID })%>
</td>
<td>
<%= Html.Encode(item.VacancyID) %>
</td>
<td>
<%= Html.Encode(item.JobTitle) %>
</td>
<td>
<%= Html.Encode(item.PositionID) %>
</td>
<td>
<%= Html.Encode(item.LocationID) %>
</td>
<td>
<%= Html.Encode(item.JobDescription) %>
</td>
<td>
<%= Html.Encode(item.JobConditions) %>
</td>
<td>
<%= Html.Encode(item.Qualifications) %>
</td>
<td>
<%= Html.Encode(item.RequiredSkills) %>
</td>
<td>
<%= Html.Encode(item.Certifications) %>
</td>
<td>
<%= Html.Encode(String.Format("{0:g}", item.AdvertDate)) %>
</td>
<td>
<%= Html.Encode(String.Format("{0:g}", item.AdvertExpiryDate)) %>
</td>
<td>
<%= Html.Encode(item.Status) %>
</td>
<td>
<%= Html.Encode(item.StaffLevel) %>
</td>
<td>
<%= Html.Encode(item.LineManagerEmail) %>
</td>
<td>
<%= Html.Encode(item.ApprovalFlag) %>
</td>
<td>
<%= Html.Encode(String.Format("{0:g}", item.RequisitionDate)) %>
</td>
</tr>
<% } %>
</table>
<p>
<%= Html.ActionLink("Create New", "Create") %>
</p>
First, if you simply want to reuse your view on multiple pages, you should be using a shared partial view (place it in the Shared folder) with <% Html.RenderPartial("OpenVacancies"); %>.
Second, based on your code snippet, your partial view doesn't appear to be strongly typed. Instead of
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
you will want something like this:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Vacancy>>" %>