✅ App advice before starting writing anything
I tried to make the app twice but got stuck/tangled into a huge mess so I'm redoing it again. Maybe the problem is with planning, I don't know. I've never done any similar things before so that's a factor too. It's just for a portfolio but tbh it'd be of use to me as well. I'm afraid it's too ambitious but I refuse to make a 1000th to-do list haha
The most basic idea is that the app searches for voice actors basing on movie titles. So when I'm watching a movie and I recognize the person, I can find out where else were they present. I'm going to use a MediaWiki API, it's neat.
I'm not sure if it's up to date but I'm assuming I'll be using MVC architecture. The wiki's results come in JSON so classes for it can be generated by VisualStudio, this will go into the Model part.
Next I have to deserialize it into something usable, that's the Controller part I guess? Viewing is in View, that's pretty straightforward.
So far I had the most issue with connecting View to Controller. I used <input> in a <form> element, is this correct? I know it's hard to say anything without code but I deleted it all 😅 I'll be posting updates but I'd like to get something to build on first. It's weird that any tutorials are either old or difficult to understand, is it normal?
9 Replies
Uhh, so the title asks for app advice, but you seem to progress quite nicely already.
For the controller part: You can use
@using (Html.BeginForm("ActionName", "Controllername", FormMethod.Get)){ }
and wrap your input in that. I think you can also define an action on a <form> itself, but i don't remember how that is done.I have a general idea, it's the details that destroy me 😆
in MVC, there are 3 important parts to understand.
Model, View, Controller.
a "Model" is more than just your json class, its an object that can pass data to and from your view/controller
a view is a mix of html and C# code that ONLY cares about showing information
a controller handles the HTTP stuff and also does/dispatches any and all application logic that is needed (sending API requets, parsing the results etc)
So a request to your MVC app will be handled by a controller, which fetches data and calculates a model, then passes that model to a view which is finally rendered and your user gets a nice html webpage to see
I read that it's better to move API related stuff to Services but I'm not sure if this makes sense in such a small scale project
In general, it makes sense. It might be a good practice to do 🙂
if you dont feel like it, you can just throw everything into the controller
But I dont recommend that
what himmdawg just said.
I personally really like commands/handlers and using result types to handle only HTTP stuff in the controller
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.in the meantime it turned out I was using the wrong template so that explains some of the confusion
btw since that's a template and has a looot of weird files, how do I deal with uploading it on github? I'm sure I'll break something if I'll try to remove seemingly unnecessary files but on the other hand it doesn't feel right to just send all of them there.
And there's another thing now. I have a "search bar" where the user inputs a movie title. This title is then pasted into a url and I receive a result of this search, a list of movies.
I want to display them as a list so I made a new view for this. The template project has a similar thing, two views can be selected from a menu. What I don't understand is that they're connected to Home controller like this
Is it just how the template is made? I thought that for each view there has to be a separate controller and they just "meet" in that main window
No, each view doesnt have its own controller. Each controller has 0 or more views, that it renders when it feels like it.
You usually match your views to "actions" (public methods in the controller), but thats not a hard requirement
In the example you pasted just now, do you see the
asp-controller
and asp-action
attributes on the links? that means ASP will check the route for those and calculate the URL for you