Telerik Forums
UI for ASP.NET MVC Forum
1 answer
3.6K+ views
I am new to mvc, new telerik. I have page with several sections: section A to G, and a button to register.
Section A contains an Asp.Net MVC Grid.
I would like to save this data to db only after filling all the sections. However I should be able to save the section A data in grid to the associated viewmodel each time a row is added, updated, deleted. I have tried below code as per samples provided on the telerik website, but I am unsuccessful. Please could you help me on how will be be able to achieve this?

My object model for the page looks like below:

namespace SampleProject.Models
{
public class Base {
public Guid Id {get; set;}
public string Name{get; set;}
}
public class Person : Base {
public string TelephoneNumber {get; set;}
public string FaxNumber {get; set;}
public string EmailAddress {get; set;}
}
public class Order {
public Order()
{
Persons = new List<Person> ();
}
public List<Person> Persons {get; set;}
}

}

namespace SampleProject.ViewModels
{
public class RegisterViewModel
{
public RegisterViewModel()
{
Order = new Order();
}
    Order Order {get; set;}
}
}

VIEw:
@model SampleProject.ViewModels.RegisterViewModel
 @(Html.Kendo().Grid<SampleProject.Models.Person>()
                                    .Name("PersonGrid")
                                    .Columns(columns =>
                                    {
                                        columns.Bound(c => c.Name);
                                        columns.Bound(c => c.TelephoneNumber).Title("Telephone Number");
                                        columns.Bound(c => c.FaxNumber).Title("Fax Number");
                                        columns.Bound(c => c.EmailAddress).Title("Email Address");
                                        columns.Command(command =>
                                        {
                                            command.Edit();
                                            command.Destroy();
                                        }).Title("Actions").Width(250);
                                    })
                                    .ToolBar(toolbar => toolbar.Create())
                                    .Editable(editable => editable.Mode(GridEditMode.InLine))
                                    .HtmlAttributes(new { style = "height: 150px;" })
                                    .Scrollable()
                                    .Sortable()
                                    .DataSource(dataSource => dataSource
                                                .Ajax()
                                                .Model(model => model.Id(c => c.Id))
                                                .Create(create => create.Action("CreatePerson", "Register"))
                                                .Update(update => update.Action("UpdatePerson", "Register"))
                                                .Destroy(delete => delete.Action("DeletePerson", "Register"))
                                                .Read(read => read.Action("ReadPersons", "Register"))
                                                )
                                )

Controller:
public class RegisterController
{
private RegisterViewModel registerViewModel;
public ActionResult RegisterNewOrder()
        {           
            return View(registerViewModel);
        }

public ActionResult ReadPersons([DataSourceRequest] DataSourceRequest request)
        {
            return Json(registerViewModel.Order.Persons.ToDataSourceResult(request),
                        JsonRequestBehavior.AllowGet);
        }

[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult CreatePerson([DataSourceRequest] DataSourceRequest request, Person person)
        {
            if (person != null)
            {
                person.Id = Guid.NewGuid();
                if (ModelState.IsValid)
                {
                    var xPerson = new Person
                    {
                        Id = person.Id,
                        Name = person.Name,
                        TelephoneNumber = person.TelephoneNumber,
                        EmailAddress = person.EmailAddress,
                        FaxNumber = person.FaxNumber
                    };
                    registerViewModel?.Order?.Persons.Add(xPerson);
person.Id = xPerson.Id;
                }
            }
            return Json(new[] { person }.ToDataSourceResult(request, ModelState));
        }

[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult UpdatePerson([DataSourceRequest] DataSourceRequest request, Person person)
        {
            if (ModelState.IsValid)
            {
                var xPerson = registerViewModel.Order.Persons
                                       .FirstOrDefault(x => x.Id == person.Id);
                //TODO: Need to find out exact
                if (xPerson  != null)
                {
                    xPerson .Name = person.Name;
                    xPerson .TelephoneNumber = person.TelephoneNumber;
                    xPerson .FaxNumber = person.FaxNumber;
                    xPerson .EmailAddress = person.EmailAddress;
                }
            }
            return Json(new[] { person }.ToDataSourceResult(request, ModelState));
        }
[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult DeletePerson([DataSourceRequest] DataSourceRequest request, Person person)
        {
            if (person != null && ModelState.IsValid)
            {
                registerViewModel?.Order?.Persons.Remove(person);
            }
            return Json(new[] { person }.ToDataSourceResult(request, ModelState));
        }
}

Thanks,
Sreeni

Boyan Dimitrov
Telerik team
 answered on 13 Sep 2019
1 answer
364 views

I have a Grid with a custom popup editor. Inside the popup editor, I have a MultiColumnComboBox.

 

When I select a value in the MultiColumnComboBox and click Update button in the editor, the Update method does not get fired. When I console out e.model on the save event, dirty flag is false, dirtyFields is empty and contact_id is null.

 

@Html.LabelFor(model => model.contact_id)
@(Html.Kendo().MultiColumnComboBoxFor(model => model.contact_id)
                .AutoBind(false)
                .Placeholder("Select Contact...")
                .DataTextField("contact_number")
                .DataValueField("id")
                .Columns(columns =>
                {
                    columns.Add().Field("contact_number").Title("Id");
                    columns.Add().Field("contact_name").Title("Name");
                })
                .Filter(FilterType.Contains)
                .DataSource(source =>
                    {
                        source.Read(read =>
                            {
                                read.Action("SearchContact", "Manager").Data("getContactData").Type(HttpVerbs.Post);
                            })
                            .ServerFiltering(false);
                    })
                )
Viktor Tachev
Telerik team
 answered on 13 Sep 2019
1 answer
137 views

I am pretty new to MVC/Telerik and am having an issue populating a grid. I created the standard Telerik MVC5 project with the Grid and menu. I added my model, created a context and updated the controllers and views. When i run the app on the Visual Studio IIS Express instance i have zero issues. However, once i publish it to an IIS 8 test server i receive HTTP 500 errors and an empty grid.Looking at the Fiddler results it appears that the read function on grid is the issue.

 

Grid Controller

public partial class GridController : Controller
{   
        public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
        {         
            using (var ctx = new CWDataContext())
            {
                IQueryable<CWDataModel> carts = ctx.CW_Data;
                DataSourceResult result = carts.ToDataSourceResult(request);
                return Json(result);
            }
        }
}

 

Home Controller

 public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
            return View();
        }
    }

 

Model

   [Table("CWCartLblFile")]
    public class CWDataModel
    {
        [Key]
        public int Row_ID { get; set; }
        public string COLOR { get; set; }
        public string SKU { get; set;

    }

 

Context

public class CWDataContext : DbContext
    {
        public CWDataContext() : base("defaultString")
        {            
        }
        public DbSet<CWDataModel> CW_Data {get; set;}
}

 

Index View

<div class="row">
    <div class="col-12">
        @(Html.Kendo().Grid<TelerikMvcApp1.Models.CWDataModel>()
            .Name("grid")
            .Columns(columns =>
            {
                columns.Bound(product => product.COLOR).Width(50);
                columns.Bound(product => product.SKU).Width(50);
            })
            .Pageable()
            .Sortable()
            .Scrollable()
            .Filterable()
            .HtmlAttributes(new { style = "height:550px;" })
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(20)
                .Read(read => read.Action("Orders_Read", "Grid"))
            )
        )
    </div>
</div>

 

I am not sure if something in the code is incorrect or i overlooked something on the web server.

 

Mark A
Top achievements
Rank 2
 answered on 12 Sep 2019
2 answers
131 views

After upgrading to UI for ASPNET MVC 2019.2.619, default values defined in the grid's datasource section are no longer populating. This was working in a previous version.  Now when clicking the new button, the fields are blank.  Below is just an example.  No code was changed from the previous version.  This is for pop-up editing with a template.  Any help would be appreciated.

 

.Model(model =>
 {
     model.Id(m => m.TruckKey);
     model.Field(f => f.DriverName).DefaultValue("Driver Name");
 })
Tsvetomir
Telerik team
 answered on 12 Sep 2019
8 answers
726 views

Hi,

I have a standard grid with a NumericTextBoxFor field using inline editing in a MVC5 project.

The NumericTextBoxFor is configured to show 5 digits after the decimal separator in both the editor-template and the HTML code.

The problem is, that the 5 digits is only shown if the NumericTextBoxFor is selected when in edit mode or if not in edit mode at all - otherwise only 2 rounded digits is shown.

Any idea ?

I have a proof-of-concept to show, if this is new to you.

Thank you in advance.

Brian
Top achievements
Rank 1
 answered on 11 Sep 2019
1 answer
319 views

Hello

I am searching for example usage of the Telerik controls to create a user interface for a one-to-many relationship.

For example, a form for an Invoice; and the lower portion of the form has a grid for the user to create multiple line items.

This is a common UI, but I'm unable to find anything. Any help is appreciated.

 

Thanks!

Petar
Telerik team
 answered on 10 Sep 2019
1 answer
123 views

Hi

 

I am having an issue with the grid. I am using GridEditMode.PopUp. If I click create to open the PopUp and then press cancel, it inserts a blank row into the grid

Viktor Tachev
Telerik team
 answered on 10 Sep 2019
1 answer
481 views

Before version 2019.2 I used MobileSwitch for checkboxes and when I want to clear a form I did this:

1._form.reset();
2.$(_form).find("[type=checkbox]").each(function () {
3.      $("#" + this.id).data("kendoMobileSwitch").refresh();
4.})

 

Now, using Switch, I've changed line 3 to

$("#" + this.id).data("kendoSwitch").refresh();

but that didn't work.

 

How can I achieve the same with new Switch?

Ezequiel
Top achievements
Rank 2
 answered on 09 Sep 2019
1 answer
945 views

     Hello,

I am  new to MVC and Telerik. I am trying to devise a way to globally change themes (both those that come with Kendo in the C:\Program Files (x86)\Progress\Telerik UI for ASP.NET MVC R2 2019\styles folder and ones created via the SASS Theme builder.

I see the "Change Themes" drop down list at: https://demos.telerik.com/aspnet-mvc/dropdownlist 

and the https://docs.telerik.com/kendo-ui/styles-and-layout/change-themes-on-the-client

but I am curious as to how we would go about creating a dynamic list of all the themes that come with Telerik and all user created sass themes and apply them globally for a user AND be able to save that theme so it is loaded for a user and applied every time they visit the site and the ability to change the theme and save

that preference at anytime. Thoughts?

Thanks,

Petar
Telerik team
 answered on 09 Sep 2019
3 answers
321 views

As I've been learning about the grid, I've noticed in most of your examples, the grid is being call from a jquery ready function.  Can you explain this technique, or probably better, point me to documentation that explains this to me. 

 

 

Nikolay
Telerik team
 answered on 09 Sep 2019
Narrow your results
Selected tags
Tags
Grid
General Discussions
Scheduler
DropDownList
Chart
Editor
TreeView
DatePicker
ComboBox
Upload
MultiSelect
ListView
Window
TabStrip
Menu
Installer and VS Extensions
Spreadsheet
AutoComplete
TreeList
Gantt
PanelBar
NumericTextBox
Filter
ToolTip
Map
Diagram
Button
PivotGrid
Form
ListBox
Splitter
Application
FileManager
Sortable
Calendar
View
MaskedTextBox
PDFViewer
TextBox
Toolbar
Dialog
MultiColumnComboBox
DropDownTree
Checkbox
Slider
Switch
Notification
Accessibility
ListView (Mobile)
Pager
Security
ColorPicker
DateRangePicker
Wizard
Styling
Chat
DateInput
MediaPlayer
TileLayout
Drawer
SplitView
Template
Barcode
ButtonGroup (Mobile)
Drawer (Mobile)
ImageEditor
RadioGroup
Sparkline
Stepper
TabStrip (Mobile)
GridLayout
Badge
LinearGauge
ModalView
ResponsivePanel
TextArea
Breadcrumb
ExpansionPanel
Licensing
Rating
ScrollView
ButtonGroup
DropDownButton
CheckBoxGroup
NavBar
ProgressBar
QRCode
RadioButton
Scroller
Timeline
TreeMap
TaskBoard
OrgChart
Captcha
ActionSheet
Signature
DateTimePicker
AppBar
BottomNavigation
Card
FloatingActionButton
Localization
MultiViewCalendar
PopOver (Mobile)
Ripple
ScrollView (Mobile)
Switch (Mobile)
PivotGridV2
FlatColorPicker
ColorPalette
AIPrompt
PropertyGrid
ActionSheet (Mobile)
BulletGraph
Button (Mobile)
Collapsible
Loader
CircularGauge
SkeletonContainer
Popover
HeatMap
Avatar
ColorGradient
CircularProgressBar
SplitButton
StackLayout
TimeDurationPicker
Chip
ChipList
DockManager
ToggleButton
Sankey
OTPInput
ChartWizard
SpeechToTextButton
InlineAIPrompt
TimePicker
StockChart
RadialGauge
ContextMenu
ArcGauge
AICodingAssistant
SmartPasteButton
PromptBox
SegmentedControl
LLM Kit
+? more
Top users last month
Tien
Top achievements
Rank 1
Iron
Krasimir
Top achievements
Rank 3
Bronze
Iron
Iron
Cedar
Top achievements
Rank 1
Iron
Emil
Top achievements
Rank 1
Iron
Kyle Watson
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Tien
Top achievements
Rank 1
Iron
Krasimir
Top achievements
Rank 3
Bronze
Iron
Iron
Cedar
Top achievements
Rank 1
Iron
Emil
Top achievements
Rank 1
Iron
Kyle Watson
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?