[Razor] Populating form values from controller

  1. #1

    [Razor] Populating form values from controller

    Hi there,

    I'm just having some issues populating a form with data that I must retrieve from the controller. There are many examples in webforms but I'm just wondering what the best way to do this in Razor views would be. Basically I have a details view which receives an ID parameter into its controller method and retrieves the necessary data but now I'm not sure what to do with it. Must I create a store for the form and some sort of listener or can I simply set up the relevant model object for my form view (as you do in normal MVC) and then just set the text field values (for instance) as Model.Fieldname etc.? It seems like there are several ways to achieve the same thing and I'm not sure about the advantages/disadvantages of the various approaches?
  2. #2
    What about just passing your data as a model to your view and binding your controls from your Model? You don't need to make your controllers and views complicated, remember to KISS ... that's the whole idea of MVC :)

    @model MyNamespace.Models
    
    @(Html.X().FormPanel()
        ....
        .Items(a =>
        {
            a.Add(Html.X().TextField()
                .Name("FirstName")
                .Text(Model.FirstName)
        } )
    )
    Cheers,
    Timothy
  3. #3
    Hi,

    +1 to Timothy.

    The following links might be helpful as well.
    http://forums.ext.net/showthread.php...ll=1#post80909
    http://msdn.microsoft.com/en-us/gg618479

Similar Threads

  1. [CLOSED] [RAZOR] How to access ext.net controls from controller method
    By gets_gui in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Sep 13, 2012, 8:12 AM
  2. [CLOSED] Get value from textfield in controller [Razor]
    By boris in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 10, 2012, 7:19 PM
  3. Replies: 1
    Last Post: Apr 09, 2012, 1:07 PM
  4. Multicombo box not populating values in edit mode
    By vs.mukesh in forum 1.x Help
    Replies: 1
    Last Post: Jan 21, 2011, 8:26 AM
  5. Replies: 5
    Last Post: Jan 04, 2011, 8:09 PM

Posting Permissions