Hi Team
How do get URL for your download button if you have Homecontroller? I have created View but i want that download but within my form. Example is below;
- // HomeController
- //GET/Download_Report
- public ActionResult Download_ExcelReport()
- {
- //var _db = new eNtsaRegistration();
- var data = (from q in db.eNtsaRegForms select new {
- Id = q.Id,
- Title = q.Title,
- FirstName = q.FirstName,
- LastName = q.LastName,
- Position =q.Position,
- Company = q.Company,
- StreetAddress = q.StreetAddress,
- StreetAddressLine = q.StreetAddressLine,
- City = q.City,
- StateProvince = q.StateProvince,
- ZipCode = q.ZipCode,
- Email = q.Email,
- CellNumber = q.CellNumber,
- Country = q.Country,
- DietaryRequirements = q.DietaryRequirements
- }).ToList();
- ReportDocument rpt = new ReportDocument();
- rpt.Load(Server.MapPath("~/Reports/TrainingAcademy.rpt"));
- rpt.SetDataSource(data);
- // rpt.Refresh();
- Response.Buffer = false;
- Response.ClearContent();
- Response.ClearHeaders();
- try
- {
- Stream stream = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);
- stream.Seek(0, SeekOrigin.Begin);
- return File(stream, "application/vnd.ms-excel", "eNtsaRegistrationForm.xls");
- }
- catch
- {
- throw;
- return View();
- }
- }
- // View of Download_XMLReport
- @model eNtsaRegistrationTraining.Models.RegViewAndRoleViewModel
- @{
- ViewBag.Title = "Download_ExcelReport";
- }
Download_ExcelReport
- @using (Html.BeginForm())
- {
- @Html.AntiForgeryToken()
- class="form-horizontal">
- @Html.ValidationSummary(true, "", new { @class = "text-danger" })
class="form-group">class="col-md-offset-2 col-md-10">- "submit" value="Create" class="btn btn-default" />
- }
- @Html.ActionLink("Back to List", "RegFormSave")
- // View Form
- @model eNtsaRegistrationTraining.Models.RegViewAndRoleViewModel
- @{
- ViewBag.Title = "SubmitRegDetails";
- List
CountryLIstData = new List (); - foreach (var data in Model.CountryLIst)
- {
- SelectListItem selectList = new SelectListItem();
- selectList.Text = data.Text;
- selectList.Value = data.Value;
- CountryLIstData.Add(selectList);
- }
- }
- @if(User.IsInRole("SuperAdmin")) {
-
- class="z-inex" style="width:1000px;">class="register-logo">class="card">class="card-body register-card-body">
"~/Images/eNtsa.png" />
Training Course Registration:Motion MasterClass
Course date: 25-27 February 2020
- Note:Please note your registration is submit approval as seats for this course is limited. Once your registration is confirmed, you will receive a quote for subject to your confirmation
- followed by an invoice.
- @using (Html.BeginForm("SubmitRegDetails", "Home", FormMethod.Post))
- {
class="form-horizontal">
class="form-group row">- ="Title" class="col-sm-2 col-form-label">Title
class="col-sm-3 ">- @Html.EditorFor(model => model.RegForm.Title, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.RegForm.Title, "", new { @class = "text-danger" })
class="form-group row">- ="Name" class="col-sm-2 col-form-label">Name:
class="col-sm-3 ">- @Html.EditorFor(model => model.RegForm.FirstName, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "Name" } })
- @Html.ValidationMessageFor(model => model.RegForm.FirstName, "", new { @class = "text-danger" })
class="col-sm-3">- @Html.EditorFor(model => model.RegForm.LastName, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "LastName" } })
- @Html.ValidationMessageFor(model => model.RegForm.LastName, "", new { @class = "text-danger" })
class="form-group row">- ="Position" class="col-sm-2 col-form-label">Position:
class="col-sm-3">- @Html.EditorFor(model => model.RegForm.Position, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.RegForm.Position, "", new { @class = "text-danger" })
class="form-group row">- ="Company" class="col-sm-2 col-form-label">Company:
class="col-md-3">- @Html.EditorFor(model => model.RegForm.Company, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.RegForm.Company, "", new { @class = "text-danger" })
class="form-group row">- ="Addresss" class="col-sm-2 col-form-label">Address*
class="col-sm-5">- @Html.EditorFor(model => model.RegForm.StreetAddress, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "Street Address" } })
- @Html.ValidationMessageFor(model => model.RegForm.StreetAddress, "", new { @class = "text-danger" })
class="form-group row">- ="Address" class="col-sm-2 col-form-label">
class="col-sm-5">- @Html.EditorFor(model => model.RegForm.StreetAddressLine, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "Street Address Line 2" } })
- @Html.ValidationMessageFor(model => model.RegForm.StreetAddressLine, "", new { @class = "text-danger" })
class="form-group row">- ="City" class="col-sm-2 col-form-label">
class="col-sm-3">- @Html.EditorFor(model => model.RegForm.City, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "City" } })
- @Html.ValidationMessageFor(model => model.RegForm.City, "", new { @class = "text-danger" })
- ="State/Province" class="col-form-label">
class="col-sm-3">- @Html.EditorFor(model => model.RegForm.StateProvince, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "State/Province" } })
- @Html.ValidationMessageFor(model => model.RegForm.StateProvince, "", new { @class = "text-danger" })
class="form-group row">- ="ZipCode" class="col-sm-2 col-form-label">
class="col-sm-3">- @Html.EditorFor(model => model.RegForm.ZipCode, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "ZipCode", id = "textZipCode" } })
- @Html.ValidationMessageFor(model => model.RegForm.ZipCode, "", new { @class = "text-danger" })
- @using (Html.BeginForm("Index", "Home", FormMethod.Post))
- {
class="col-sm-3">- @Html.DropDownListFor(model => model.RegForm.Country, CountryLIstData as List
) - }
class="form-group row">- ="Email" class="col-sm-2 col-form-label">Email:
class="col-sm-4">- @Html.EditorFor(model => model.RegForm.Email, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "Email", id = "textEmail" } })
- @Html.ValidationMessageFor(model => model.RegForm.Email, "", new { @class = "text-danger" })
- class="text-danger" style="display:none">This field is required
class="form-group row">- ="Attendee" class="col-sm-2 col-form-label">Attendee Cell Number*
class="col-sm-3">- @Html.EditorFor(model => model.RegForm.CellNumber, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "Cell Number", id = "textCellNumber" } })
- @Html.ValidationMessageFor(model => model.RegForm.CellNumber)
class="form-group row">- ="Verify not a human" class="col-sm-2 col-form-label">Please verify you not a human*
class="col-sm-3">- @using (Html.BeginForm("FormSubmit", "GetCapatcha", FormMethod.Post))
- {
class="g-recaptcha" data-sitekey="6LcLN6cZAAAAABbgHtWziQB9nsWNXqZcpBnLU6dd">- }
class="form-group row">- ="col-sm-2 col-form-label">Dietary requirements:
class="col-sm-3">class="form-check">- @Html.CheckBoxFor(model => model.DietMain.None, new { @class = "form-check-input" })
- ="form-check-label" for="@Html.IdFor(m => m.DietMain.None)">None
class="form-check">- @Html.CheckBoxFor(model => model.DietMain.Vegetarian, new { @class = "form-check-input" })
- ="form-check-label" for="@Html.IdFor(m => m.DietMain.Vegetarian)">Vegetarian
class="form-check">- @Html.CheckBoxFor(model => model.DietMain.Vegan, new { @class = "form-check-input" })
- ="form-check-label" for="@Html.IdFor(m => m.DietMain.Vegan)">Vegan
class="form-check">- @Html.CheckBoxFor(model => model.DietMain.Halaal, new { @class = "form-check-input" })
- ="form-check-label" for="@Html.IdFor(m => m.DietMain.Halaal)">Halaal
class="form-check">- @Html.CheckBoxFor(model => model.DietMain.Other, new { @class = "form-check-input" })
- ="form-check-label" for="@Html.IdFor(m => m.DietMain.Other)">Other
class="form-group">class="col-md-offset-2 col-md-10">- "submit" value="Submit" class="btn btn-primary" />
class="form-group">class="col-md-offset-2 col-md-10">- "submit" value="Download" class="btn btn-danger" />
- }
- @Html.ActionLink("Back to list", "SaveRegForm")
- }
- "font-size:20px;margin:20px;padding:20px;border:1px; solid#ff0000">
- @ViewData["Message"]
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jenith ThakkarPosted Aug 7, 2020, 7:19 AM
Thank you