This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Razor views as email templates
I am sending out an email to the user from within my service of my website.
I want to format this so that it shows nice and a specific way.
Here is what I have:
<table bgcolor="#FFE680" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td width="100%" height="51" valign="middle"><h1> <strong>[COMPANY] User ID Reminder </strong></h1></td>
<td align="right" valign="top" width="8"><img alt="" width="8" height="8" align="top" /></td>
</tr>
</tbody>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td align="left" valign="top" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td colspan="1" align="left"></td>
</tr>
<tr>
<td align="left" valign="top" width="100%"><p> <br />
Dear [USERNAME], </p>
<p> In response to your request to be reminded of your User ID, please find below the information we have on file for you. If you didn't submit this request, ignore this email. </p>
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>Your User ID is: </td>
<td>[USERNAME]</td>
</tr>
<tr>
<td>Your registered email address is: </td>
<td>[EMAIL]</td>
</tr>
</tbody>
</table>
<p>
If you have forgotten your password, you can request it here.<br />
</p>
<p>
Thank you,<br />[COMPANY]
</p></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
Now my question isn't about the looks of the email but how do I put this as the body of my email while populating the appropriate fields?
I put it in resources as a string and I figured I'd just do a replace of the specific [fields]. This starting becoming tedious and seemed sloppy:
var body = SuburbanHUB.Properties.Resources.ForgotPasswordEmailBody.Replace("[USERNAME]", username).Replace("[EMAIL]")...
I'm sure there is a better way of doing this but I have not the experience.
=== CLARIFICATION ===
I am using razor to call a WCF service written in C#. The service that is being called is where the email is being sent from and not the view. I am using Razor with MVC with C# as the underlying code.
I'm in the middle of trying to do the same thing. We're using Razor templates to generate the email, and passing in a Model which has all the various variables to fill it out. This lets us include everything that Razor and MVC support, including #if and #Html.Partial, which lets us construct an email from pieces.
The answer we just went with involves running an internal MVC webserver, requesting pages from it with the Model as a parameter, and capturing the response text, but there's variants on my question that are more self contained. Take a look and see if any of the other answers or comments help you.
I had similar requirement and I end up using NVelocity and it worked great for me. Please see this article for a workthrough http://www.codeproject.com/Articles/12751/Template-merging-with-NVelocity-and-ASP-NET. You have to modify your fields in the template according to the velocity templating language. Download NVelocity from http://nvelocity.sourceforge.net/.
Related
What I have is this:
<table>
<tr bgcolor="#007ACC" style="color:White">
<td width="145">Account Group</td>
<td width="80"></td>
<td width="10">Active</td>
</tr>
<tr>
·
·
</tr>
</table>
What I need to do is make it so "Account Group" can be changed based on a user's treeview selection. i.e., if the user selects a Child node, I need to change that to "Account Number".
Is it possible to change a table element on-the-fly like that? If so, how would I do this?
Place a label in <td> to display text, so that you can change them based on label id
<td width="145">
<asp:Label Text="Account Group" ID="lblUserContent" runat="server" />
</td>
As per treeview selection changes you can change the text by using following code:
if(your condition)
lblUserContent.Text="Account Number"
else
lblUserContent.Text="Account Group"
The best way to do this will depend on how you're using your treeview, but here's a quick way to output the value of a C# variable into your table:
<table>
<tr bgcolor="#007ACC" style="color:White">
<td width="145"><%# Eval("MyCSharpVariable") %></td>
<td width="80"></td>
<td width="10">Active</td>
</tr>
<tr>
·
·
</tr>
</table>
i am developing an asp.net c# application using the twitter bootstrap framework.
i am trying not to add change or add any CSS so wanted to know the following
i have a asp.net gridview, which eventually renders as table. i wanted to know what is the css class to be applied for tables?
ASP.NET
C#
Twitter Bootstrap
<table cellspacing="0" rules="all" border="1" id="VideoList" style="border- collapse:collapse;">
<tr>
<th scope="col"> </th><th scope="col"> </th>
</tr><tr>
<td>Senior Care</td><td>
</td>
</tr><tr>
<td>Cardiac Catheterization Lab</td><td>
</td>
</tr>
</table>
any ideas will be much appreciated.
Well the minimum styling can be added just with the "table" class. That is:
MyGrid.CssClass = "table";
Optionally, you can include additional table formatting such as
MyGrid.CssClass = "table table-striped table-bordered";
To see some more noticeable styling
I have a html table in my ASPX page and would like to use it in code-behind for some processing. The table is shown as below:
<table class="hovertable" id="tblData">
<tr>
<th>ID:</th>
<td colspan="3" style="font-weight: bold">
<%= Eval("ID") %>
</td>
</tr>
<tr>
<th>Date:</th>
<td><%# Eval("Date", "{0:dd-MMM-yyyy}") %></td>
<th>Amount:</th>
<td><%# Eval("Amount", "{0:C}") %>
</tr>
</table>
However, when I add the runat="server" attribute to my table, I am produced with the following error:
CS1502: The best overloaded method match for 'System.Web.UI.HtmlControls.HtmlTableRowCollection.Add(System.Web.UI.HtmlControls.HtmlTableRow)' has some invalid arguments
Any ideas what may be wrong here? Am I missing out anything?
An html table (which is not a pure asp.net server control) can't contain asp.net server controls. Take a look at this answer:
http://forums.asp.net/t/1524580.aspx/1
In my opinion, you should ask yourself the following question?
Do i need to solve this client or server side?
if your answer is client, you should implement the update logic with Ajax, otherwise you could use the ASP.NET server control and implement it server side.
OK guys, I have solved this issue by myself. The problem causing it was because of a <td> not having the corresponding <tr> element.
It was something like below:
<table class="hovertable" id="tblData">
<tr>
<th>ID:</th>
<td colspan="3" style="font-weight: bold">
<%= Eval("ID") %>
</td>
</tr>
<tr>
<th>Date:</th>
<td><%# Eval("Date", "{0:dd-MMM-yyyy}") %></td>
<th>Amount:</th>
<td><%# Eval("Amount", "{0:C}") %>
</tr>
<td colspan='4'>
Some data....
</td>
</table>
I think you can use this for the same purpose
<asp:Table ID="Table1" runat="server">
</asp:Table>
What you are trying to do is adding runat="server" attribute to a HTML control
Try adding <asp:Labels> where you need to manipulate data.
<table>
<tr><td><asp:Label id="lblRow" runat="server" /></td></tr>
</table>
Table columns and rows cannot be accessed via code behind if you have runat="server" in the tag because they are pure html.
Another way is to use a StringBuilder to create the html table in the code-behind and and asp:LiteralControl to output the table.
Also if we remove the tbody element it will not throw error for td mismatch
Nikhil Mittal
Remove the below elements
<thead>
</thead>
<tbody>
</tbody>
I have a table similar to the one below which I would like to convert into an rss feed somehow. What is the best way to approach this? Should I be scraping the contents and trying to build up an rss or is there a much simpler annd easier way (I'm hoping)? I'm using the asp.net / c# - anyone point me to any tutorials out there that will help me achieve this would be great:)
<table align="left" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td align="left" valign="top" style="width: 125px; height: 125px;" colspan="1"><img title="Costa Rica" alt="Costa Rica" src="/CR_sq.jpg?n=4185" /></td>
<td align="left" valign="top" colspan="1"><strong><font color="#fff" size="2">Costa Rica <br /></font><span class="SubHeadingGrey_7_0">16 August 2012</span></strong><br /><br />Some Text Here <a title="...read on" href="/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=1234">...read on</a></td>
</tr>
<tr>
<td align="left" valign="top" style="width: 125px; height: 125px;"><img width="117" height="117" title="South Africa" style="width: 117px; height: 117px;" alt="AL 2012 Icon" src="/SA2012.jpg?width=117&height=117&mode=max" /></td>
<td align="left" valign="top"><p><strong><font color="#fff" size="2">South African Story<br /></font><span class="SubHeadingGrey_7_0">16 August 2012</span></strong></p>
<p>This is summary text <a title="... read on" href="/SA.aspx">... read on</a></p>
</td>
</tr>
<tr>
<td align="left" valign="top" style="width: 125px; height: 125px;"><img title="ITALY" alt="ITALY" src="/Italy.jpg?n=43" /></td>
<td align="left" valign="top"><strong><font color="#fff" size="2">Italian Article<br /></font><span class="SubHeadingGrey_7_0">15 August 2012</span></strong><br /><br />Italian Visit Article<a title="...read on" href="/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=1256">...read on</a></td>
</tr>
</tbody>
</table>
As long as the html is well formed and matches XML you can read it in as xml and then use XSLT to convert it to an rss feed using XslTransform here is a simple example of how to use xlsTransform http://www.xmlfiles.com/articles/cynthia/xslt/default.asp
I am using jtemplate(jquery) , in which i have a htm file as below
<table width="100%" border="0" cellpadding="0" cellspacing="2">
<tr class="dark_color">
<th>
Offer
</th>
</tr>
{#foreach $T.TransList as record}
<tr class="{#if ($T.record$index % 2) == 0} white_left {#else} dark_color {#/if}">
<td class="offer" align="left">
{$T.record.OfferName}
</td>
</tr>
{#/for}
</table>
I am filling data using below code in my aspx page -
$("#jtemplateGrid_" + lastID).setTemplateURL('JTemplate/gridTemplate.htm');
// process the template
$("#jtemplateGrid_" + lastID).processTemplate(data)
;
Now i want to use global variable in my htm page.
How we can done the same.
Thanks in advance
What you could do is to send a get parameter with it and split it using JavaScript or whatever you'd like on the page to check up on it or use it.
Not clear on how it could be done otherwise but it is a possibility.