python - In what form should data be passed onto View? -


let's assume i'm following 'traditional' mvc pattern desktop applications (a simple crud app) using wxpython.

the model utilises peewee orm interface postgres db. these objects are, obviously, custom classes , view has no idea them.

let's define part class here:

class part(basemodel): part_number = pw.charfield() kind = pw.charfield() description = pw.charfield() unit = pw.charfield(db_column = 'unit') 

the user clicks button , 'edit part' window pops up. window needs show part's details.

the question is, model pass above class' instance view , view accesses instance's properties? (mypart.part_number)

or convert them more simpler form list or dictionary?

are using controller?. controllers integral part of model-view-controller pattern. act glue between model , view. need create view model , pass model through controller. please see example below.

assume have viewmodel this

public class reportviewmodel {    public string name { set;get;} } 

and in action,

public actionresult report() {   return view(new reportviewmodel()); } 

and view must typed reportviewmodel

@model reportviewmodel @using(html.beginform()) {   report name : @html.textboxfor(s=>s.name)   <input type="submit" value="generate report" /> } 

and in httppost action method in controller

[httppost] public actionresult report(reportviewmodel model) {   //check model.name property value   //to : return } 

or simply, can without poco classes (viewmodels)

@using(html.beginform()) {    <input type="text" name="reportname" />    <input type="submit" /> } 

and in httppost action, use parameter same name textbox name.

[httppost] public actionresult report(string reportname) {   //check reportname parameter value   //to : return } 

edit : per comment

if want post controller, may use overload of beginform method.

@using(html.beginform("report","someothercontrollername")) {    <input type="text" name="reportname" />    <input type="submit" /> } 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -