MVC Model Bind

Page 2 of 2 FirstFirst 12
  1. #11
    Hi Nurkmez,

    I'll try this one out. Then i can use it as a temporary solution.
    thanx a lot!
  2. #12
    Hello,

    I am afraid we can't get it working as you need, because we don't have a good way to intervene the process of deserializing of an action's parameters. Please correct me if I am wrong.

    You could do it manually if needed.

    Example 1
    public ActionResult Submit(ProductModel ProductModel)
    {
        ProductModel.ComboValue1 = JSON.Deserialize<IEnumerable<ListItem>>(this.Request["_ComboValue1_state"]).ElementAt<ListItem>(0); // The ElementAt will require a check on null if no selected item in the ComboBox
        ProductModel.ComboValue2 = JSON.Deserialize<IEnumerable<ListItem>>(this.Request["_ComboValue2_state"]);
    
        X.Msg.Alert("ProductModel", JSON.Serialize(ProductModel)).Show();
        return this.Direct();
    }
    Setting up a ComboBox's ValueHiddenName property you can change a submit key.

    Example 2
    Html.X().ComboBoxFor(m => m.ComboValue1).Items(Model.Data).ValueHiddenName("ComboValue1"),
    Html.X().ComboBoxFor(m => m.ComboValue2).Items(Model.Data).ValueHiddenName("ComboValue2"),
    public ActionResult Submit(ProductModel ProductModel)
    {
        ProductModel.ComboValue1 = JSON.Deserialize<IEnumerable<ListItem>>(this.Request["ComboValue1"]).ElementAt<ListItem>(0); // The ElementAt will require a check on null if no selected item in the ComboBox
        ProductModel.ComboValue2 = JSON.Deserialize<IEnumerable<ListItem>>(this.Request["ComboValue2"]);
    
        X.Msg.Alert("ProductModel", JSON.Serialize(ProductModel)).Show();
        return this.Direct();
    }
  3. #13
    Quote Originally Posted by Daniil View Post
    Hello,

    I am afraid we can't get it working as you need, because we don't have a good way to intervene the process of deserializing of an action's parameters. Please correct me if I am wrong.

    You could do it manually if needed.

    Example 1
    public ActionResult Submit(ProductModel ProductModel)
    {
        ProductModel.ComboValue1 = JSON.Deserialize<IEnumerable<ListItem>>(this.Request["_ComboValue1_state"]).ElementAt<ListItem>(0); // The ElementAt will require a check on null if no selected item in the ComboBox
        ProductModel.ComboValue2 = JSON.Deserialize<IEnumerable<ListItem>>(this.Request["_ComboValue2_state"]);
    
        X.Msg.Alert("ProductModel", JSON.Serialize(ProductModel)).Show();
        return this.Direct();
    }
    Setting up a ComboBox's ValueHiddenName property you can change a submit key.

    Example 2
    Html.X().ComboBoxFor(m => m.ComboValue1).Items(Model.Data).ValueHiddenName("ComboValue1"),
    Html.X().ComboBoxFor(m => m.ComboValue2).Items(Model.Data).ValueHiddenName("ComboValue2"),
    public ActionResult Submit(ProductModel ProductModel)
    {
        ProductModel.ComboValue1 = JSON.Deserialize<IEnumerable<ListItem>>(this.Request["ComboValue1"]).ElementAt<ListItem>(0); // The ElementAt will require a check on null if no selected item in the ComboBox
        ProductModel.ComboValue2 = JSON.Deserialize<IEnumerable<ListItem>>(this.Request["ComboValue2"]);
    
        X.Msg.Alert("ProductModel", JSON.Serialize(ProductModel)).Show();
        return this.Direct();
    }
    Thanks Vladimir,

    I did not try your solution. It will solve the problems. Thanks...
  4. #14
    Quote Originally Posted by nurkmez View Post
    Thanks Vladimir,

    I did not try your solution. It will solve the problems. Thanks...
    If Ext.Net can serialize or deserialize complex model on next version, EXT.NET will gain huge advantages over competitors. I hope that you will add your work item.

    Thanks you very much..
  5. #15
    Quote Originally Posted by Daniil View Post
    I am afraid we can't get it working as you need, because we don't have a good way to intervene the process of deserializing of an action's parameters. Please correct me if I am wrong.
    My colleague, Vladimir, corrected me.

    Please take a look at the following example.
    http://mvc.ext.net/#/DataView_Basic/Overview/

    There is the following action.
    public ActionResult SubmitSelectionWithValues([ModelBinder(typeof(JsonModelBinder))]Dictionary<string, string>[] images)
    A ModelBinder attribute is used to affect the deserialization process.

    JsonModelBinder
    public class JsonModelBinder : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var vpr = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
            if (vpr == null || vpr.AttemptedValue.IsEmpty())
            {
                return null;
            }
            return JSON.Deserialize(vpr.AttemptedValue, bindingContext.ModelType);
        }
    }
    So, if you need custom deserialization, you should implement a binder like the JsonModelBinder one and pass it to a ModelBinder attribute.

    Also it is possible to set a [ModelBinder] attributed for a class.

    [ModelBinder(...)]
    class ProductModel 
    {
        ...
    }
    Another approach is associating a type and a binder in Global.asax.

    Hope this helps.
    Last edited by Daniil; Mar 27, 2013 at 4:11 PM.
  6. #16
    [QUOTE=Daniil;105622]My colleague, Vladimir, corrected me.

    Sorry Daniil

    Thanks for your guide.
  7. #17
    No problem!

    We will appreciate any information about your progress on this issue.
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 1
    Last Post: Nov 20, 2012, 9:27 AM
  2. RESTful MVC bind Model to Store
    By Dominik in forum 1.x Help
    Replies: 6
    Last Post: Nov 10, 2011, 2:34 PM
  3. [1.0] Int64 bind bug
    By qq899817 in forum Bugs
    Replies: 3
    Last Post: Jan 09, 2011, 12:42 PM
  4. About Store Bind?
    By GeoffreyRen in forum 1.x Help
    Replies: 2
    Last Post: Jul 07, 2009, 10:22 PM
  5. how to bind ....
    By izee in forum 1.x Help
    Replies: 0
    Last Post: Mar 23, 2009, 12:32 AM

Tags for this Thread

Posting Permissions