using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FormsAuthenticationMVC.Models;
using System.Runtime.Caching;
using System.Data.SqlClient;
namespace FormsAuthenticationMVC.Controllers
{
//[Authorize]
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpGet]
public ActionResult Reports(string ReportName)
{
TempData["ReportName"] = ReportName;
ViewBag.Message = "O2 Dashboard";
ASP_AuthEntities ReportTable = new ASP_AuthEntities();
{
if(ReportName != null)
{
Session.Remove("EmbedCode");
string EmbedCode = ReportTable.Database.SqlQuery<string>("SELECT [EmbedCode] FROM asp.Report_Security WHERE [ReportName] = @param1", new SqlParameter("@param1", ReportName)).FirstOrDefault();
HttpContext.Session["EmbedCode"] = EmbedCode;
}
}
return View();
}
[HttpPost]
[ValidateInput(false)]
public ActionResult Reports(Report_Security model, string ReportName)
{
return View();
}
}
}
So yeah first time around works just as i want it to, but second time. If i click on a different image that will have a different param value, The value is not passed through to the httpGet parameter
Learn the input type=image" if you are interested in learning how to use the HTML 5 tag to submit a form. It does not make sense to design a form then override the form with the onclick event. Pick one design direction.
I think the design works once because there's an Index View and a Report View. The Index View works while the Report View has the type="image" attribute inputs which submits x and y parameters in the URL.
I recommend using standard HTML and MVC helpers. Also, I don't see any reason to use JavaScript (or a form) when you can use a link.
@{
ViewBag.Title = "Reports";
}
<h2>@TempData["ReportName"]</h2>
<table style="width:100%;">
<tr style="text-align:center; margin-bottom:5000px">
<td>
<h2>O2 Dashboard</h2>
</td>
</tr>
<tr style="text-align: center">
<td style="padding:20px">
<a href="@Url.Action("Reports", "Home", new {ReportName = "PO Tracker" })">
<img src="~/Images/O2 Dashboard.png" />
</a>
<a href="@Url.Action("Reports", "Home", new {ReportName = "Where am I spending my money" })">
<img src="~/Images/O2 Dashboard.png" />
</a>
<a href="@Url.Action("Reports", "Home", new {ReportName = "ReportName=Data Table" })">
<img src="~/Images/O2 Dashboard.png" />
</a>
</td>
</tr>
</table>
Member
35 Points
375 Posts
@Url.Action only works first time
Jan 30, 2020 08:30 AM|masterdineen|LINK
Hello there.
In my view i have 3 images with URL.Action, each one passes a different parameter to a HttpGet ActionResult httpGet in a controller.
First time a click on any of the images runs great, but when i click on a different on, the HttpGet ActionResult the ReportName param is null.
See view below.
See Controller below
So yeah first time around works just as i want it to, but second time. If i click on a different image that will have a different param value, The value is not passed through to the httpGet parameter
Can someone suggest anything i a missing please
All-Star
53001 Points
23596 Posts
Re: @Url.Action only works first time
Jan 30, 2020 12:38 PM|mgebhard|LINK
Learn the input type=image" if you are interested in learning how to use the HTML 5 tag to submit a form. It does not make sense to design a form then override the form with the onclick event. Pick one design direction.
https://www.w3schools.com/tags/att_input_type_image.asp
I think the design works once because there's an Index View and a Report View. The Index View works while the Report View has the type="image" attribute inputs which submits x and y parameters in the URL.
I recommend using standard HTML and MVC helpers. Also, I don't see any reason to use JavaScript (or a form) when you can use a link.
Member
35 Points
375 Posts
Re: @Url.Action only works first time
Jan 30, 2020 01:03 PM|masterdineen|LINK
Excellent
Thank you Mgebhard
i am learning i promise LOL