I am trying to implement request a quote functionality where a customer can send out a quote request. My customer does not want a Wishlist functionality so I planned to tweak around it. I changed all the labels that were already exists for the WishList and I changed it such that it reads with "Quote List", "Quote Request Form", "Send a Quote Request" instead of "Email a Friend". I set up the default email address such that Quote Request is directly sent to the Sales Email address.
Now when the quote request is sent to the store sales team I am trying to get the HTML view and send it as Inline HTML of an email. I copy pasted the Wishlist view, models and controllers and I gave a new name "QuoteRequestEmail", and in that I removed the layout option of the view, and all the editable portion of the view. I removed the additional buttons and fields out of the duplicated view.
After that, when a user clicks on the "Request a Quote" button (originally Email a Friend button) user will be redirected to the form where on click of Send button I load the newly created view (duplicated) in a string and send it as a HTML body of an email. So basically newly created view just generates a table with all the products selected, and I am trying to send out that products list as an Email's Body HTML.
I have created a route for the new view and when I access the view through the URL it works fine but while loading it up from a WishList "Send Email" controller method it does not work properly. It does not load view's HTML in a String and the basic error of the view is It gets Null Error for the Model of a newly created view.
I created following function which returns an string of a view.
public string ToHtml(string viewToRender, ViewDataDictionary viewData, ControllerContext controllerContext)
{
var result = ViewEngines.Engines.FindView(controllerContext, viewToRender, null);
ViewEngineResult viewResult = System.Web.Mvc.ViewEngines.Engines.FindView(controllerContext, viewToRender, "");
var output = new StringWriter();
var viewContext = new ViewContext(controllerContext, result.View, viewData, controllerContext.Controller.TempData, output);
result.View.Render(viewContext, output);
result.ViewEngine.ReleaseView(controllerContext, result.View);
return output.ToString();
}
under the
public ActionResult EmailWishlistSend(WishlistEmailAFriendModel model, bool captchaValid)
I used the following code to load view on string.
if (ModelState.IsValid)
{
//Prepare the Email body Content
string _body = Core.Html.HtmlHelper.FormatText(model.PersonalMessage, false, true, false, false, false, false);
// added by Elisha Cornelius to prepare quote request email.
// get list of products to be included on the email and send the reuqest to the store owner.
Following is the code portion which calls the method to load view in a string.
this.ViewData.Model = new Models.ShoppingCart.QuoteRequestEmailModel();
_body = ToHtml("QuoteRequestEmail", new ViewDataDictionary(new ViewDataDictionary() { { "ShoppingCart", true } }), this.ControllerContext);
_workflowMessageService.SendWishlistEmailAFriendMessage(_workContext.CurrentCustomer,
_workContext.WorkingLanguage.Id, model.YourEmailAddress, "[email protected]",
Core.Html.HtmlHelper.FormatText(model.PersonalMessage, false, true, false, false, false, false));
model.SuccessfullySent = true;
model.Result = _localizationService.GetResource("Wishlist.EmailAFriend.SuccessfullySent");
return View(model);
}
Can somebody please guide me on this functionality implementation, and where I am going wrong and what exactly needs to be done for this.
Thanks Much,
Elisha Cornelius