0
votes

What is the best approach to have a kind of edit form for the site visiter with umbraco?

A very simple example is an application (Website) that has 2 pages.

First page: a list of countries.

So in umbraco i created a document type with template called "List" there is a Surface controller that gets called when the page is visited. That controller gets a list of countries (lets say from a list of objects)

public class Country 
{
    public Guid Id { get; set; }
    public string Name { get; set; }

    public Country(string name)
    {
        Id = new Guid(); //Or something likewise... whatever
        Name = name;
    }
}

List<Country> countries = new List<Country>();
countries.add(new Country("UK"));
countries.add(new Country("US"));
countries.add(new Country("France"));
countries.add(new Country("Belgium"));

The surface controllers gets this object back and renders a list of these countries in its razor view, next to each country there is a button called "Change this country"

Back in Umbraco, i also have a second document type with template called "Edit" This should be used for some Editing mechanics of that Country...

I would also prefer to have a routing like this

http(s)://localhost:12345/Edit/2354

instead of

http(s)://localhost:12345/Edit?id=2354

What is the best thing to do that? I have tried it with surface controllers, but i can't post back I have tried with Route Hijacking and completely hijacked the MVC route.

I have also searched many hours on the internet. but i cant find a good solution for this very simple problem. at least in my opinion this problem is very simple :) but i just can't get my head around it.

I hope someone is around that can solve this.

2
I disagree with the other poster that you don't need a surface controller in this case, but please post your controller code first and edit your model because I'm not sure what's your model exactly or what's the response you get.Jabberwocky

2 Answers

0
votes

Looks like you don't need to use a Surface controller for this, simply use the standard MVC structure, create a standard Controller, and your corresponding View and Model. Use a HttpGet ActionResult to return your page and then create a new update ActionResult to update your items, by passing the Country Id. Please see this standard Microsoft documentation for some details. https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/getting-started

0
votes

And did a bit of more research for you, here is a good example which explains this nicely, this might also help you to sort out your problem if you don't want to go for my first option. https://codeshare.co.uk/blog/how-to-create-a-contact-form-in-umbraco-using-mvc-and-c/