I recently received a request from a client to create a method that would allow them to directly email a user from an admin account from the contents of a completed form.
Controller:
[HttpGet]
public ActionResult ThisView() {
thisModel model = new thisModel();
emailAddress = model.EmailAddress
return Content('<a href="mailto:"model.emailAddress"', "text/html")
}
View:
<div class="form-group">
<div class="col-sm-2 raw-value"><span class="WebsiteContent" data-ControlID="divPOC_Email" data-Component="11"></span></div>
<div class="col-sm-5">
@Html.TextBoxFor(m => m.EmailAddress, new { @class = "form-control", @placeholder = "sample@email.com", maxlength = 100 })
@Html.ValidationMessageFor(m => m.EmailAddress)
</div>
<div class="col-sm-10 col-sm-offset-2 col-xs-12 field-validation-error userErrorMessage hidden" data-valmsg="user">Required</div>
</div>
The data is being retrieved from a user input, and returned to an administrator view of the completed form. The request is to pass the email address as a clickable link that will allow them to email the user directly from the form. Is it possible to pass the model data directly into the view as a raw HTML String containing the existing data?
Your question extremely unclear. It looks like you might be using a child action here, but even that doesn't really make sense.
If you want to display the value on your model as a link, you need only use Html.DisplayFor
:
@Html.DisplayFor(m => m.EmailAddress)
The default display template for an email address is to wrap it in a link. This assumes, of course that you're decorated your EmailAddress
property with [EmailAddress]
and/or [DataType(DataType.EmailAddress)]
.