Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Controller Code:
EmailModel _m = new EmailModel();
                        if (Ads.Email != null)
                        {
                            _m.toAddress.Add(Ads.Email);
                            _m.Url = "http://www.bedspacefinders.com/PostBedAds/AllPostBeds/" + be.AdvertisementID;
                            _m.Subject = "Welcome Your Ads is Live ";
                            _m.Body= System.IO.File.ReadAllText(Server.MapPath("~/EmailTemplate/EmailFormat.html"));

I want to access m.Url value in HTML template here how i can get



HTML
<div class="main-div">
            <p>
                <ul style="color:#666">
                    <li>Your ad is now live you can check through this link _m.url.</li>


What I have tried:

i want to get model value from controller to HTML view not in razor view
how its possible?
Posted
Updated 4-Jun-17 22:20pm
v2

1 solution

Add a "Url" property to the model you are passing to the view and set it to _m.url, or put _m.url in the ViewBag and show that;

Controller;

ViewBag.Url = _m.url;


View

<li>Your ad is now live you can check through this link @ViewBag.Url</li>


Though you'll probably want to render an "a" tag to make it clickable.
 
Share this answer
 
Comments
Aitzaz Ahsan 5-Jun-17 4:23am    
This answer is valid if you are using Razor view Engine i am not using razor view engine i am using just Plain HTML
F-ES Sitecore 5-Jun-17 4:28am    
You'll need to do something like put a token in your html
<li>Your ad is now live you can check through this link [url]</li>

Read the html into a variable and replace [url] in the text

string email = System.IO.File.ReadAllText(Server.MapPath("~/EmailTemplate/EmailFormat.html");
email = email.Replace("[url]", _m.url);

then use "email" in your model.

_m.body = email
Aitzaz Ahsan 5-Jun-17 15:38pm    
Please can you explain in detail i am unable to understand

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900