Step-2
Then right click near Contact() and select Go To View as shown below.
Then it displays view of the contact page.
Step-3
After opening View of the Contact Page. we need to create page with details for sending mail such as YourName, Company Name, Email, Contents etc.
<div class="form-horizontal">
@using (Html.BeginForm("Contact","Home"))
{
@Html.AntiForgeryToken();
<div class="form-group">
<label class="col-md-2 control-label">Category*</label>
<div class="col-md-4">
<select name="Category" id="Category" class="form-control">
<option value="Contact us">Contact Us</option>
<option value="Company registration">Company registration</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">YourName</label>
<div class="col-md-4">
<input type="text" name="YourName" class="form-control" placeholder="YourName" required />
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">CompanyName</label>
<div class="col-md-4">
<input type="text" class="form-control" name="CompanyName" placeholder="Company Name" required />
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Your Email Id*</label>
<div class="col-md-4">
<input name="Email" type="email" class="form-control" placeholder="Your email id" required />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2">Contents</label>
<div class="col-md-4">
<textarea class="form-control text-box multi-line" rows="10" name="Contents" placeholder="Submit Content" required></textarea>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label"></label>
<div class="col-md-7">
<div class="g-recaptcha" data-sitekey=" "></div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Submit" class="btn btn-success" />
</div>
</div>
}
</div>
Here we have created forms with label names and we have button in the last form, Here we are sending email by clicking on button, After creating the view page output appears as
Step-4
After creating View page we have create action method of the Contact in Home Controller
public ActionResult Contact()
{
ViewBag.Message = "Your contact page";
return View();
}
Step-5
After opening the Home controller we have to create Action method Contact and then we have to create Action method for Contact and we have call the form s created in view page with label names as shown below.
public ActionResult Contact()
{
ViewBag.Message = "Your contact page";
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Contact(FormCollection form)
{
string category = form["Category"];
string yourName = form["YourName"];
string companyName = form["CompanyName"];
string email = form["Email"];
string contents = form["Contents"];
EmailSender.SendEmail("webmaster@" + impFunctions.DomainName(), "", "", "", category, contents, System.Net.Mail.MailPriority.High, true);
ViewBag.SuccessMessage = "Thanks, we have received your email and will get back to you shortly.";
return View();
}
Here we have Action method of the Contact , where we have public ActionResult Contact(FormCollection form) binds the view page of the Contact in Controller and we have declared string names as Category, Your Name, CompanyName, Email, Contents with form values and in the next line we are having EmailSender.SendEmail() which is used to send mail to given domainname.
In order to send mail we have to select category, Name, Company Name and Email id, then if we click the submit button mail will be sent to following given mail and after mail has sent it shows a message "Thanks, we have received your email and will get back to you shortly.