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

[Solved] Insert popup with defaults from server

3 Answers 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
20Below
Top achievements
Rank 1
20Below asked on 03 Oct 2011, 04:59 PM
Hi,
I have an example working with a pop-up insert. It works fine except for the fact that the form doesn't have the defaults I want for the object to be inserted. I have the Insert method with the HttpPost attribute to save what is being filled out in the form, that works fine. However, my similar get function that returns a model with some defaults I want (ex. the current date) isn't coming back, I'm getting the min date. The get method isn't being hit when I click the "insert" button to pull up the popup. Example:
public ActionResult Insert()
       {
           return View(new ObjectWithDefaults() { IsActive = true, StartDate = DateTime.Now });
       }

Can someone tell me how I can get this to work? I realize that maybe this could be done client side but there are complex objects that will need pulldowns for which I will need to set defaults for as well.
Thanks.

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 05 Oct 2011, 08:13 AM
Hi,

In order to set default values for grid insert form you should use the Editable setting DefaultDataItem property:

.Editable(editing => editing
   .DefaultDataItem(new EditableProduct {ProductID = 42, LastSupply = DateTime.Now.AddDays(22) }))

All the best,
Rosen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
20Below
Top achievements
Rank 1
answered on 05 Oct 2011, 12:37 PM
Hi,
I appreciate the reply but this isn't what I was looking for. In my question I asked for a solution to get a default object from the server and show it in the popup. Your solution is for me to set the defaults on the client level but I can see how you could have thought this is a "server side" solution, so again I appreciate the reply. The problem here is that we may need to set defaults for complex objects that requires querying the database. Can someone from Telerik recommend a method of returning a default object from the server and displaying it in a popup using the Grid? This is a standard pattern in ASP .Net MVC, i.e., making an http get call to a Create method which returns View with the model to create. Please see my previous code example.
Thanks
0
Rosen
Telerik team
answered on 06 Oct 2011, 08:00 AM
Hello,

The approach suggested is indeed a server-side solution as this is code executed on the server when the View is rendered. If you meant that you need to set the default object in the Controller, than you may pass it through the VIewData/ViewBag and then assign it to the DefaultDataItem.

If you continue to experiencing difficulties please provide a small runnable project which demonstrates them.

Regards,
Rosen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
20Below
Top achievements
Rank 1
Answers by
Rosen
Telerik team
20Below
Top achievements
Rank 1
Share this question
or