i had a form in which i want a url of the page from which it got there. Like i am on /Content/Form and i got there from /Content/Document( i want to save this in my database) . what is the best way for this scenario?
Model View Controller (MVC) MVC is a design pattern used to decouple user-interface (view), data (model), and application logic (controller). This pattern helps to achieve separation of concerns.
They are the same thing. C# is the language you have used to do your development, but ASP.NET MVC is the framework you used to do it.
It is no longer in active development. It is open-source software, apart from the ASP.NET Web Forms component, which is proprietary. ASP.NET Core has since been released, which unified ASP.NET, ASP.NET MVC, ASP.NET Web API, and ASP.NET Web Pages (a platform using only Razor pages).
Basically, ASP.NET is a web delivery mechanism that runs either C# or VB.NET in the background. C# is a programming language that runs ASP.NET as well as Winforms, WPF, and Silverlight.
HttpContext.Request.UrlReferrer
The best way is to simply pass this information to the controller action.
So for example you could include the request url as a hidden field:
<% using (Html.BeginForm("Process", "SomeController")) { %>
<%= Html.Hidden("requestUrl", Request.RawUrl) %>
<input type="submit" value="OK" />
<% } %>
and inside the corresponding controller action :
[HttpPost]
public ActionResult Process(string requestUrl)
{
// requestUrl will contain the url of the page used to
// render the form
...
}
You could also use the controller and action from route data:
<% using (Html.BeginForm("Process", "SomeController")) { %>
<%= Html.Hidden("controllerName", ViewContext.RouteData.GetRequiredString("controller")) %>
<%= Html.Hidden("actionName", ViewContext.RouteData.GetRequiredString("action")) %>
<input type="submit" value="OK" />
<% } %>
and both controllerName
and actionName
will be sent in the POST request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With