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

[Solved] passing the model on popup 2

2 Answers 89 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.
william
Top achievements
Rank 1
william asked on 15 Jul 2011, 10:19 AM
Hi All,
Here's an update on my original problem.

My partial view starts:
@model GRID.ViewModels.ComputerBreakdownRiskViewModel
@{
    ViewBag.Title = "Index";
}
@Html.Hidden("policyZoneID", ViewData["policyZoneID"])
@Html.Hidden("sectionID", ViewData["sectionID"])
@(Html.Telerik().Grid(Model.Covers)
      .Name("risksGrid")
      .Sortable()
      .DataKeys(keys => keys.Add(r => r.Id))
      .DataBinding(dataBinding =>
      {
          dataBinding.Ajax()
                    .Update("_SaveAjaxEditing", "ComputerBreakdownRisk", Model.Covers);
      })

My Risk view model That populates the grid come from a complex type on the ViewModel:

public IEnumerable<CoverType> Covers { get; set; }
 
 
        #region Complex Types
 
        public class CoverType
        {
            [ScaffoldColumn(false)]
            public int Id { get; set; }
            public string Name { get; set; }
            public int SumInsured { get; set; }
            public decimal Rate { get; set; }
            public int Excess { get; set; }
            public decimal IncreasedXSDiscount { get; set; }
            public bool UseDiscount { get; set; }
            [ScaffoldColumn(true)]
            [UIHint("NotEnabledForMoney")]
            public decimal TechnicalPrice { get; set; }
        }
 
        #endregion
 
        #region LookUp Type Properties
 
        public IEnumerable<SelectListItem> CoverTypes { get; set; }
 
        #endregion

Now when I receive the popup on screen when I get into the  controller declared as :
[AcceptVerbs(HttpVerbs.Post)]
       [GridAction]
       public ActionResult _SaveAjaxEditing(int Id, ComputerBreakdownCover cover)
       {
           cover.CBCoverTypeID = Id;
           cover.CreatedBy = "Test";
           cover.CreatedOn = DateTime.Today;
           cover.ModifiedOn = DateTime.Today;
            
           
           return View(new GridModel(cover));
       }
cover now passes the values from the popup.  I have a couple of problems. At this point I do not want to save the data against the context thus updating the database, I only want to update the main view. If I attempt to pass the complete model everything is null and I suspect this is because I have not passed the whole view on the Grid i.e.
@(Html.Telerik().Grid<GRID.ViewModels.ComputerBreakdownRiskViewModel>()
If I attempt to return as above, I receive an error that states that it's not IEnumerable. All I want to do is pass the original view along with the cover. Take the cover values in the controller update the viewmodel and return. Further in my page I have a main save button, which is where I want to post everything back to the database.

update.........
changing my databinding (using the Q2 release)....
dataBinding.Ajax()
                    .OperationMode(GridOperationMode.Client)
                    .Update("_SaveAjaxEditing", "ComputerBreakdownRisk", new { this.Model, Model.Covers });
then in my controller

[AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _SaveAjaxEditing(int Id, ComputerBreakdownRiskViewModel viewModel, ComputerBreakdownCover cover)
        {
            cover.CBCoverTypeID = Id;
            cover.CreatedBy = "Test";
            cover.CreatedOn = DateTime.Today;
            cover.ModifiedOn = DateTime.Today;
 
 
            IEnumerable<ComputerBreakdownRiskViewModel.CoverType> coverFlatData = _gridService.PopGrid(cover);
           // viewModel.Covers = coverFlatData;
 
            return View(new GridModel(coverFlatData));
        }
my cover hold details from the popup as I want,  but the viewmodel is empty this is my problem. If I can get the base viewmodel passing in as well, I would be able to do what I want. to help visualise my problem I have attached a screenshot. the grid has been populated with default values, at this point when the user presses an edit button the popup appears, when I press the update button on the popup I only want to update the dingle line on the grid without doing a full postback to the DB. THe postback to the DB happens on the Save Button.

2 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 17 Jan 2012, 04:37 PM
Hi,

Did you ever solve your problem here as I'm trying to do a very similar thing.

I have a Razor based page with two Telerik MVC grids on (each bound to a separate enumable property of the viewmodel  say ViewModel.A and ViewModel.B) and I need to be able to edit the contents of grids purely on the client and then post the content of the two grids back to the controller when a separate Save button is clicked on the page (which does the post on the whole html form).

As an example of when I want to upgrade the grid contents.  One of my grids starts off blank and I have a Telerik tree next to it that is bound other data.  The user selects an item in the tree and then clicks a button to add that particular string in as a new grid row - they can do this for any amount of tree items.  Once they're happy with what they've selected in the tree (which would now be seen as items listed in the grid) they hit the save button.  The second grid is pretty much the same approach.

Is this possible?  As when I hit the save button and the form is posted back to the Controller, both ViewModel.A and ViewModel.B are null.

Thanks
0
william
Top achievements
Rank 1
answered on 17 Jan 2012, 05:34 PM
I'm afraid we could not get the popup working and gave up trying to use them. We simply force the user to a new view, not as elegant bit it did the job. We did think about doing a JQuery popup, but the code involved seemed to out weigh a new view.
Tags
Grid
Asked by
william
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
william
Top achievements
Rank 1
Share this question
or