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

Cant Access the form data in create.cshtml page

2 Answers 74 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Pritam
Top achievements
Rank 1
Pritam asked on 08 May 2013, 07:53 AM
Hello,
I'm working on a sample form to understand how to work with KendoUI, Asp.net MVC3 and MySql database.
I have created the form as a View on Create action of the controller but I cant seem to get the model to store the data inputed into the form.
 I need to know how to link the Kendo control to my model.

Create.cshtml
@model MvcApplication_Movie.Models.movie_master
@{
    ViewBag.Title = "Create";
}
<h2>Add New Movie</h2>

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
                <h3>Movie Name:</h3>
                <input type="text" id="movie_name" class="k-textbox"/>
                
                 <br />

                <h3>Release Date:</h3>
                 @(Html.Kendo().DatePicker()
                              .Name("datepicker")
                              .HtmlAttributes(new { style = "width:150px" })
                  )

                <br />

               <h3>Movie Poster:</h3>
                @(Html.Kendo().Upload().Name("files"))

                 <br />

               <input type="submit" id="submit" onclick="ins_mod()" value="Add Movie" class="k-button" />
    </fieldset>
}

The controller method
[HttpPost]
        public ActionResult Create(movie_master movie_record)
        {
            
            try
            {
                // Insert Movie logic here
                using (var insert = new moviesEntities())
                {
                    insert.movie_master.Add(movie_record);
                    insert.SaveChanges();
                }
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

Please help me asap. Thank you

2 Answers, 1 is accepted

Sort by
0
Pritam
Top achievements
Rank 1
answered on 08 May 2013, 12:34 PM
I realised dat I require certain helpers so i changed my code as follows:-
                <div class="k-textbox">
                @Html.TextBoxFor(model => model.Movie_Name)
                @Html.ValidationMessageFor(model => model.Movie_Name)
                </div>
                
                 <br />

                <h3>Release Date:</h3>
           
                @(Html.Kendo().DatePickerFor(model => model.Release_Date).Format("dd/MM/yyyy")
                                                                .Enable(true)
                                                                )
                 
           Now the basic  Html helpers fetch the inputed data but the Html.Kendo() helpers are inactive on the web page. Please help me correct the code. Thankyou

0
Daniel
Telerik team
answered on 10 May 2013, 07:26 AM
Hello Pritam,

The ModelBinder will not be able to parse the date if it is not in the expected format for the current culture. Please try to remove the Format method or set a format based on the application culture. The alternative is to create a custom ModelBinder or parse the value from the form data in the action.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
General Discussions
Asked by
Pritam
Top achievements
Rank 1
Answers by
Pritam
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or