Combobox helper sends a null value into the model.

9 posts, 0 answers
  1. Pritam
    Pritam avatar
    16 posts
    Member since:
    Jan 2013

    Posted 09 May 2013 Link to this post

    I'm working on Asp.net MVC3 application with KendoUI. Database is MySql.
    Its a sample movie application.
    This is my model:-
            public int Movie_ID { get; set; }
            public string Movie_Name { get; set; }
            public Nullable<System.DateTime> Release_Date { get; set; }
            public string Movie_Type { get; set; }
            public string Movie_Cert { get; set; }
            public string Movie_Poster { get; set; }
            public string Movie_Budget { get; set; }
            public bool Awards { get; set; }

    This is the view:-
    <h2>Add a Movie:-</h2>
     
     <br/>
     @using (Html.BeginForm("Create", "New_Movie",FormMethod.Post, new { id = "uploadForm", enctype = "multipart/form-data" }))
     {
        @Html.ValidationSummary(true)
        <fieldset>
     <label class="k-label">Movie Name:</label>
     <div class="k-textbox">
     @Html.TextBoxFor(m => m.Movie_Name)
     </div>

      <br/>
      <br/>
      <label class="k-label">Release Date:</label>
      @(Html.Kendo().DatePickerFor(m => m.Release_Date)

            .Name("Release_Date")

       )

      <br/>
      <br/>

     <label class="k-label">Movie Type:</label>

        @(Html.Kendo().ComboBoxFor(m => m.Movie_Type)
        .Name("Mov_Type")
        .Placeholder("Select Type...")
        .BindTo(new string[]
                    {"Action",
                    "Comedy",
                    "Documentary",
                   "Suspense Thriller"}
                )
    )
    <label class="k-label">Movie Budget:</label>
          @(Html.Kendo().DropDownListFor(m => m.Movie_Budget)
                        .Name("Budget")
                        .BindTo(new string[] {
                                  "1 to 25 crores",
                                  "26 to 50 crores",
                                  "51 to 75 crores",
                                  "above 76"
                              })
      )
    <input type="submit" name="submit" value="Submit" />      
           
           </fieldset>
     }

    Now when i submit this page to the controller create()

      [HttpPost]
            public ActionResult Create( movie_master movie_record)
            {
                     using (var insert = new moviesEntities())
                    {
                        insert.movie_master.Add(movie_record);
                        insert.SaveChanges();
                    }
                    return RedirectToAction("Index");
            }
     the model object movie_record contains Movie_Type=null and Movie_Budget=null.
     The Kendo datapicker returns the date value selected.
    What am i doing wrong ? Please help me.
  2. Simant Bilgi Islem San. ve Tic. Ltd. Sti
    Simant Bilgi Islem San. ve Tic. Ltd. Sti avatar
    4 posts
    Member since:
    Nov 2012

    Posted 09 May 2013 Link to this post

    As i see you are using name property with combobox for. It already creates a name for the input depends on your model name. This can be the problem why it sends a null value. You need to delete name properties.
  3. Pritam
    Pritam avatar
    16 posts
    Member since:
    Jan 2013

    Posted 09 May 2013 Link to this post

    It didn't work I really don't know what the problem is as the date picker returns a value.
     Is there anything wrong with the BindTo?
  4. Simant Bilgi Islem San. ve Tic. Ltd. Sti
    Simant Bilgi Islem San. ve Tic. Ltd. Sti avatar
    4 posts
    Member since:
    Nov 2012

    Posted 09 May 2013 Link to this post

    @(Html.Kendo().DatePickerFor(m => m.Model.Activationdate)
    .HtmlAttributes(new { @class = "tt-datepicker" })
    .Format("dd/MM/yyyy")
    .Min("01/01/1900")
    )

    This is how are mines looks like. And i dont have any problem with binds.
    If you can make a online demo we can help more usefull to you.
    Do not use name property on any widget if you using model binding.
  5. Pritam
    Pritam avatar
    16 posts
    Member since:
    Jan 2013

    Posted 10 May 2013 Link to this post

    Hi ,
     I have no problems with Kendo datepicker, its just the combo box and dropdown dat return null values could you please write down a sample view for these controls.
    As I feel dat I may be going wrong in the bindto:-
    @(Html.Kendo().ComboBoxFor(m => m.Movie_Type)
        
        .Placeholder("Select Type...")
        .BindTo(new SelectList(new string[]
                    {"Action",
                    "Comedy",
                    "Documentary",
                    "Romance",
                    "Suspense Thriller"}
        ))

        .SelectedIndex(1)
        .Suggest(true)
            )
    Thanks in adv
  6. Pritam
    Pritam avatar
    16 posts
    Member since:
    Jan 2013

    Posted 10 May 2013 Link to this post

    I solved the problem using hidden fields storing selected values on Select event and den accessing the hidden field values on the controller.

  7. Simant Bilgi Islem San. ve Tic. Ltd. Sti
    Simant Bilgi Islem San. ve Tic. Ltd. Sti avatar
    4 posts
    Member since:
    Nov 2012

    Posted 10 May 2013 Link to this post

    If you use combobox's .DataValueField("Domainid")
                                            .DataTextField("Description")
    properties they will make this for you.
    Text field which user will see in list and Value field is the one which will save the database.
  8. Gusdek
    Gusdek avatar
    1 posts
    Member since:
    Apr 2017

    Posted 10 Jul in reply to Simant Bilgi Islem San. ve Tic. Ltd. Sti Link to this post

    how to set name to the value..?? when i submit my form both the text and the value got same name and this is problem for me because my combobox is dynamicly added as user like...

     

  9. Dimitar
    Admin
    Dimitar avatar
    136 posts

    Posted 12 Jul Link to this post

    Hello Gusdek,

    May I ask you to provide additional clarifications and an isolated example (with dummy data), where the described issue is demonstrated, so that I will be able to review it locally and provide you with further assistance?  

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top