MVC (Model-View-Controller)

  • Christian Chat is a moderated online Christian community allowing Christians around the world to fellowship with each other in real time chat via webcam, voice, and text, with the Christian Chat app. You can also start or participate in a Bible-based discussion here in the Christian Chat Forums, where members can also share with each other their own videos, pictures, or favorite Christian music.

    If you are a Christian and need encouragement and fellowship, we're here for you! If you are not a Christian but interested in knowing more about Jesus our Lord, you're also welcome! Want to know what the Bible says, and how you can apply it to your life? Join us!

    To make new Christian friends now around the world, click here to join Christian Chat.
W

wwjd_kilden

Guest
#1
Hi.
I haven't been doing much of this so I am still trying to wrap my mind around what belongs where.

For now I have a view class with a dataGridView that is bound to a dataset , a controller, and a model which connects to a database, and I am able to display data (yay!).

Now let's say I want to let the user be able to add a row of data to the database...

How much of the job should the view class actually do?
Should I have it create a datarow and pass it on,
or do I send a string/ array something else via the controller and let only the model class worry about datarows?
 
W

wwjd_kilden

Guest
#2
edit: or will editing the datagridview automatically edit the datset so I can just update the database with the dataadapter?
 

blue_ladybug

Senior Member
Feb 21, 2014
70,869
9,601
113
#3
Ummmmmm... I got nothing.. :( lol
 

Reformed_Goth

Junior Member
May 4, 2014
2
0
1
#4
Hey wwjd_kilden:

From what I've gathered, you want to have as little logic as possible in your view. This is to make your logic unit testable. Otherwise, you would need to do integration testing with Selenium and those tests take a long time to work.

Also, this type of question belongs on StackOverflow more than here. The tech support forum is more in regards to the site rather than development work. Go there, if you haven't already, and a lot more people will be able to give you the help you need.

Good luck!
 
W

wwjd_kilden

Guest
#5
it is for any tech related problems we have, at least that is how it has been used the years the section has existed

I've tried stackoverflow before, all they will tell me is something along the lines of "why didn't you google it" or "why don't you already know how to do this noob?"
 

JasonNosneh

Senior Member
Aug 2, 2015
110
4
18
#6
The reason they tell you to google it is because your questions are too vague and also you don't show relevant code. You don't even state what language you are using. MVC is just design pattern nothing more so it could be any language.

The point of MVC is to have separation of concerns -- the view should only be responsible for what the user sees and include no business logic or database queries. The controller handles executing business logic from actions initiated by the user. The model is typically just a plain object that provides structure for the data. To retrieve data, query the database and convert the data into an instance of a model and in the view use the model to display the data to the user, and similarly, posted data by the user would be converted into the model and then the model would be converted into queries for modifying the database.

A lot of people are ditching MVC frameworks such as ASP.NET MVC because creating models, server-side rendering in view, and all the other boiler plate required can be cumbersome and not best practice. Most people are building purely Javascript, Html, and CSS front-ends using frameworks like angularJS, ReactJS, Vue, etc. On the server-side using any language, just create a Web API that handles JSON response and requests. The is good because you can create one API that can be consumed by any device -- browser, app, desktop, etc.
 
W

wwjd_kilden

Guest
#7
I didn't provide code because my question wasn't about language specific code, but merely at what point to turn my data into database "format" (which I believe has little to do with what language I use). So thanks for answering that -


The problem is in Norway people are doing all kinds of things in a lovely tangle
(well, at least judging by what they say you must know in the IT job ads). Some of them actually specify MVC knowledge as a requrement, so I am just trying to get a hang of the basic idea of it, and half the guides out there are just as vague as my question :p
 

notmyown

Senior Member
May 26, 2016
4,646
1,100
113
#8
Hey wwjd_kilden:

From what I've gathered, you want to have as little logic as possible in your view. This is to make your logic unit testable. Otherwise, you would need to do integration testing with Selenium and those tests take a long time to work.

Also, this type of question belongs on StackOverflow more than here. The tech support forum is more in regards to the site rather than development work. Go there, if you haven't already, and a lot more people will be able to give you the help you need.

Good luck!
this is my life story. lol!

and yes, i comprehend you're not using the word 'logic' in the way i mean it.

but just barely :p
 

EarnestQ

Senior Member
Apr 28, 2016
2,588
310
83
#9
I agree that the question is vague, and even though you are asking a "generic" question, providing the code may be helpful, because the answer may be language related. One language may provide methods and objects that work better than a different language at solving your question.

However, if I understand you correctly, you are just experimenting, so why not do it both ways and see which way seems more elegant to you?

There might also be some libraries out there where others have already solved the problem.
 
W

wwjd_kilden

Guest
#10
Okai. I ditched what I was originally thinking of and started a new approach,
since what I originally view is a mix of several tables, I think it would turn chaotic to let the user add a new row :p
so now I am working on generating fields in a separate form to let the user enter info into a given table.

I will probably write myself into a corner and return with some code:D
 

breno785au

Senior Member
Jul 23, 2013
6,002
764
113
39
Australia
#11
it is for any tech related problems we have, at least that is how it has been used the years the section has existed

I've tried stackoverflow before, all they will tell me is something along the lines of "why didn't you google it" or "why don't you already know how to do this noob?"
I'm surprised you got that result from stackoverflow. People there are usually pretty helpful.
 
W

wwjd_kilden

Guest
#12
Ok, for now I ended up sending the data as a list of strings.

Here is a new question: I only recently found out you can actually load the schema information from the database into the dataset, so I am trying that out now (using C# and mysql):

----
da.Fill(ds, tablename);
da.FillSchema(ds, SchemaType.Source, tablename);
---

Once I get to the point where I try to add a row to my dataset, and then the database, what difference does the added constraints make? - Will my code throw an exception when I try to add the row to my dataset table or what happens compared to if I don't bother adding the restraints?

(The fieldlist is a list of strings containing whatever info the user inputted that is to go into the relevant table in the database)

internal void updateDB(List<string> fieldList, string tablename)
{
throw new NotImplementedException();

/*
DataRow row = ds.Tables[tablename].NewRow();

row["colname"] = stufffromlist;
(...)

ds.Tables[tablename].Rows.Add(row);
da.Update(ds);
*/
}