Having a little trouble with returning a custom view on a dynamic url, mainly through my own lack of understanding on how the process works so if someone can step in here and help me out id be extreemly grateful.
How all this works is as follows:
• a user selects the amount of tickets that are needed, on submit this hits a controller which builds up the model, ultimately hitting a RedirectToAction method:
TempData["model"] = model;
return RedirectToAction("ShowCompleteRegistrationForm");
}
public virtual ActionResult ShowCompleteRegistrationForm()
{
var model = (TicketsFormModel)TempData["model"];
return View("~/Views/CompleteRegistration.cshtml", model);
}
Now for the most part this works, however the returned url is:
/umbraco/Surface/{controllername}/{action}
I know this is where all locally created surfact controllers get mapped to, however I need this to return the current url appending on /register to the end, so for example I need:
/events/{year}/{eventName}/register
Ive looked into route hijacking but I admit I dont fully understand how all this works, especially with the dynamic nature of the returned url.
Hi Tom, thanks for the reply, added a new RouteConfig.cs file into the root of App_start and this file contains:
using System.Web.Mvc;
using System.Web.Routing;
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
name: "Register",
url: "events/{year}/{eventName}/register",
defaults: new { controller = "{controllerName}", action = "Submit" }
);
}
}
However, still this redirects to
/umbraco/Surface/{controller}/{action}
I suspect theres more to getting this to work than just adding what you put above into a file. Im really not familiar with this, so whilst the help is appreciated I would understand more with an example. Honestly, speak to me like a 5 year old here, thanks for the help.
Having trouble in returning to view by passing model along with this.
errorMessage Cannot bind source type eCaptis.Models.Patient to model type Umbraco.Core.Models.PublishedContent.IPublishedContent.
public class PatientController : SurfaceController
{
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Patient patient = db.Patients.Find(id);
if (patient == null)
{
return HttpNotFound();
}
return PartialView( patient);
}
}
I possibly suspect there is problem with the routing, as after installing Umbraco v8, Debugger is not hitting RouteConfig.cs
Bit of BackGround: I have created a document type in umbraco called home which has a child item edit and login
Home page will display a table where by clicking on name it should navigate to edit patient view, so i have passed Id of the patient to controller upon clicking the name of patient as shown in the code above.
Redirect to custom url (routing?)
Hi guys, firstly happy new year!
Having a little trouble with returning a custom view on a dynamic url, mainly through my own lack of understanding on how the process works so if someone can step in here and help me out id be extreemly grateful.
How all this works is as follows:
• a user selects the amount of tickets that are needed, on submit this hits a controller which builds up the model, ultimately hitting a RedirectToAction method:
Now for the most part this works, however the returned url is:
I know this is where all locally created surfact controllers get mapped to, however I need this to return the current url appending on /register to the end, so for example I need:
Ive looked into route hijacking but I admit I dont fully understand how all this works, especially with the dynamic nature of the returned url.
You could add a new route to your routeConfig.cs file:
Hi Tom, thanks for the reply, added a new RouteConfig.cs file into the root of App_start and this file contains:
However, still this redirects to
I suspect theres more to getting this to work than just adding what you put above into a file. Im really not familiar with this, so whilst the help is appreciated I would understand more with an example. Honestly, speak to me like a 5 year old here, thanks for the help.
Hi David,
No problem, i'll elaborate some more. When you've got the routeconfig file set-up you need to register it on the
applicationstarted
event.For more information on the topic of binding events before, during or after start-up of your application check out: https://our.umbraco.org/documentation/reference/events/application-startup
When creating a new controller which 'fetches' your request be sure to inherit from the base mvc Controller class.
For the sake of completeness the route config file looks like:
(There's no need for the default
year
andeventName
parameters to be set)The documentation also has a topic + example on creating custom routes: https://our.umbraco.org/documentation/Reference/Routing/custom-routes
Similar kind of problem as above stated by David
Hi Guys,
Having trouble in returning to view by passing model along with this.
errorMessage Cannot bind source type eCaptis.Models.Patient to model type Umbraco.Core.Models.PublishedContent.IPublishedContent.
public class PatientController : SurfaceController {
} I possibly suspect there is problem with the routing, as after installing Umbraco v8, Debugger is not hitting RouteConfig.cs
Bit of BackGround: I have created a document type in umbraco called home which has a child item edit and login
Home page will display a table where by clicking on name it should navigate to edit patient view, so i have passed Id of the patient to controller upon clicking the name of patient as shown in the code above.
Doing this my url is changing from http://localhost:12345 to http://localhost:12345/umbraco/Surface/Patient/Edit/345
In general if we dont use surface controller or Umbraco this url could be like http://localhost:12345 to http://localhost:12345/Patient/Edit/345
I have even looked into route hijacking but this did not help me or may be because of my lack of understanding.
Any help in fixing this is much appreciated Thanks in advance
is working on a reply...