This is a migrated thread and some comments may be shown as answers.

Combobox helper sends a null value into the model.

8 Answers 666 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Pritam
Top achievements
Rank 1
Pritam asked on 09 May 2013, 11:12 AM
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.

8 Answers, 1 is accepted

Sort by
0
answered on 09 May 2013, 12:57 PM
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.
0
Pritam
Top achievements
Rank 1
answered on 09 May 2013, 01:36 PM
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?
0
answered on 09 May 2013, 01:46 PM
@(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.
0
Pritam
Top achievements
Rank 1
answered on 10 May 2013, 05:20 AM
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
0
Pritam
Top achievements
Rank 1
answered on 10 May 2013, 06:59 AM
I solved the problem using hidden fields storing selected values on Select event and den accessing the hidden field values on the controller.

0
answered on 10 May 2013, 07:18 AM
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.
0
Gusdek
Top achievements
Rank 1
answered on 10 Jul 2017, 11:32 AM

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...

 

0
Dimitar
Telerik team
answered on 12 Jul 2017, 07:46 AM
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.
Tags
ComboBox
Asked by
Pritam
Top achievements
Rank 1
Answers by
Pritam
Top achievements
Rank 1
Gusdek
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or