Telerik Forums
UI for ASP.NET MVC Forum
3 answers
510 views

Hi,

I have to render my partial view in html string (in controller), to return json object.

I found this function that works very well :

01.public static String RenderViewToString(ControllerContext context, String viewPath, object model = null)
02.        {
03.            context.Controller.ViewData.Model = model;
04.            using (var sw = new StringWriter())
05.            {
06.                //var viewResult = ViewEngines.Engines.FindView(context, viewPath, null);
07.                var viewResult = ViewEngines.Engines.FindPartialView(context, viewPath);
08.                var viewContext = new ViewContext(context, viewResult.View, context.Controller.ViewData, context.Controller.TempData, sw);
09.                viewResult.View.Render(viewContext, sw);
10.                viewResult.ViewEngine.ReleaseView(context, viewResult.View);
11.                return sw.GetStringBuilder().ToString();
12.            }
13.        }

 

With a kendo grid in partial view, i'm getting a "System.NullReferenceException" on the declaration  @(Html.Kendo().Grid(.....

If I return the view with a "Return view" in my controller, it's ok.

 

My grid:

01.@(Html.Kendo().Grid((IEnumerable<MAGI.Model.DigicodeImmeuble>)mvDigicode)
02.        .Name("gridSyntheseDigicode")
03.        .HtmlAttributes(new { style = "width:100%;height: auto;", @class = "k-grid_encart k-grid_nopage" })
04.        .Columns(t =>
05.            {
06.                t.Bound(c => c.Digicode1.Nom).Title(tabTraduction[701972] + " 1");
07.                t.Bound(c => c.Digicode1.NoDigicode).Title(tabTraduction[100620]);
08.                t.Bound(c => c.Digicode2.Nom).Title(tabTraduction[701972] + " 2");
09.                t.Bound(c => c.Digicode2.NoDigicode).Title(tabTraduction[100620]);
10.            }
11.        )
12.        .Sortable()
13.        .Selectable()
14.        .DataSource(dataSource => dataSource
15.            .Ajax()
16.            .ServerOperation(false)
17.        )
18.        .Reorderable(reorder => reorder.Columns(true))
19.        .Events(events => events.DataBound("onDataBoundGridStandard"))
20.    )

 

mvDigicode and tabTraduction are not null. 

 

That's work with the kendo chart module.

What's wrong with the grid ?

 

Many thanks, 

 


 
06.                var viewResult = ViewEngines.Engines.FindPartialView(context, viewPath);
Nikolay Rusev
Telerik team
 answered on 27 Nov 2015
4 answers
1.6K+ views
HI,,

i am try to use grid view with inline editing function.

now i have write this code:-- on cshtml.

<script>

                $(document).ready(function () {

                    $("#countryzone-grid").kendoGrid({

                        dataSource: {

                            type: "json",

                            transport: {

                                read: {

                                    url: "@Html.Raw(Url.Action("ParticipatingCountry", "Program", new {id = Model.Id } ))",

                                    type: "POST",

                                    dataType: "json",

                                    contentType: "application/json"

                                },

                                create: {

                                    url: "@Html.Raw(Url.Action("EditCountries", "Program"))",

                                    type: "POST",

                                    dataType: "json"

                                },

                                update: {

                                    url:"@Html.Raw(Url.Action("SettingUpdate", "Setting"))",

                                    type: "POST",

                                    dataType: "json"

                                },

                                destroy: {

                                    url: "@Html.Raw(Url.Action("SettingDelete", "Setting"))",

                                    type: "POST",

                                    dataType: "json"

                                },

                                parameterMap: function(data, operation) {

                                    if (operation != "read") {

                                        return data;

                                    } else {

                                        //for some reasons only such "Filter" data be parsed

                                        return JSON.stringify(data);

                                    }

                                }

                            },

                            schema: {

                                data: "Data",

                                total: "Total",

                                errors: "Errors",

                                model: {

                                    id: "Id",

                                    fields: {

                                        CountryId: { editable: true, type: "number" },

                                        CountryName: { editable: true, type: "string"},

                                        PointsValue: { editable: true, type: "number"},

                                        Id: { editable: false, type: "number" },

                                        ProgramId: { editable: false, type: "number" }

                                    }

                                }

                            },

                            requestEnd: function (e) {

                                if (e.type == "create" || e.type == "update") {

                                    this.read();

                                }

                            },

                            error: function (e) {

                                display_kendoui_grid_error(e);

                                // Cancel the changes

                                this.cancelChanges();

                            },

                            pageSize: 5,

                            serverPaging: true,

                            serverFiltering: true,

                            serverSorting: true

                        },

                        pageable: {

                            refresh: true

                        },

                        sortable: true,

                        toolbar: ["create"],

                        editable: {

                            confirmation: false,

                            mode: "inline"

                        },

                        scrollable: false,

                        columns:[{

                            field: "CountryId",

                            title: "Admin.Program.participatingCountryName",

                            editor: countryDropDownEditor,

                            template: "#:Store#"

                        },{

                            field: "PointsValue",

                            title: "Admin.Program.PointsValue"

                        },{

                            command: ["edit", "destroy"], title: "",width: "200px"

                        }]    

                    });

                });

                

                

                function countryDropDownEditor(container, options) {

                    $('<input required data-text-field="Name" data-value-field="Id" data-bind="value:CountryId"/>')

                        .appendTo(container)

                        .kendoDropDownList({

                            autoBind: false,

                            dataTextField: "Name",

                            dataValueField: "Id",

                            dataSource: {

                                type: "json",

                                transport: {

                                    read: {

                                        dataType: "json",

                                        type: 'POST',

                                        url:
"@Html.Raw(Url.Action("DropDownListCountries", "Program", new {id =
Model.ClientId } ))"

                        }

                    }

                }

            });

        }

            </script>

by this code when i click on update button there is an ajax call

this is data of post tab in ajax call ( view on browser by firebug)

CountryId  0
CountryName
Id  0
PointsValue 2
ProgramId  0

there is data 0 and 2

on controlller side my code is

[HttpPost]

        public ActionResult EditCountries([Bind(Exclude = "Id")] ParticipatingCountryModel model)     <== Here i put break point 

        {

            return null;
        }

by break point i see that there is ajax call come means action call but there is an empty model ,,, alll values are 0, there is an value 2 but there is 0 why?

is am i doing wrong?

Please advice how to do?

Regard,
vinit
Stephan
Top achievements
Rank 1
 answered on 26 Nov 2015
1 answer
53 views

Hi,

We are using a detail row on one of our grids, but have noticed that there are a couple of issues with the way we have done it and I am wondering if there is a way to do the following:

 1. When we re-order the columns on the main grid, re-order the same columns on the detail row.

 2. When we re-size the columns on the main grid, re-size them on the detail row.

 The problem is that we have hard coded the order currently, but are allowing the user the ability to re-order, thus presenting us with the issues above.

Is there an easy way of achieving the above, or will it be a case of manually manipulating them both with javascript?

Cheers,

Gareth

Nikolay Rusev
Telerik team
 answered on 26 Nov 2015
1 answer
87 views

Is there are document that maps the MVC Razor syntax to the raw Kendo UI notation?

 

I find several examples using Kendo UI that suit my needs but I need to convert them to run in an MVC project.

 

It's not always clear how the syntax matches from one to the other.

 

Thanks,

Ken

Kiril Nikolov
Telerik team
 answered on 26 Nov 2015
1 answer
138 views
 Hello, I am unable to get data into my kendo grid. I have looked at many other threads but nothing has helped so far. I want to get the data from my controller / model but I am not sure if i am trying to do it correctly
 

 VIEW

@model MyProject.Models.POApprovalViewModel 
 
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
 
@{
    ViewBag.Title = "PO Approval";
}
 
<div class="container">
    <h4>PO Approval</h4>     
 
    @(Html.Kendo().Grid(Model.AssignedApprovals)
              .Name("grdPOs")
              .Columns(columns =>
              {
                  columns.Bound(model => model.PoId);
                  columns.Bound(model => model.PoStatus);
              })
              .Pageable()
              .Sortable()
              .DataSource(dataSource => dataSource
                  .Ajax()
                  .ServerOperation(true)
                  .Model(model => model.Id("PoId"))
                  .Read(read => read.Action("POApproval_Read", "POApproval"))
               )
    )
 
</div>

 

 CONTROLLER

public class POApprovalController : Controller
{
    string UserId;
    POApprovalViewModel po;
 
    // GET: POApproval
    public ActionResult Index()
    {
        po = new POApprovalViewModel();
        return View(po);
    }
 
    [HttpPost]
    public ActionResult POApproval_Read()
    {
        dbPOApproval db = new dbPOApproval();
        return Json(db.GetAssignedApprovals());
    }
}

 

MODEL

    public class POApprovalViewModel
   {
       public List<OLAssignedApprovals> AssignedApprovals
       {
           get
           {
               if (_AssignedApprovals == null)
               {
                   _AssignedApprovals = new List<OLAssignedApprovals>();
               }
               return _AssignedApprovals;
           }
       }
 
       private List<OLAssignedApprovals> _AssignedApprovals;
   }   
 
   public class OLAssignedApprovals
   {
       public int PoId { get; set; }
       public string PoStatus { get; set; }
   }
 
   public class dbPOApproval
   {
       MyDataSourceOjbect objPOApproval = new MyDataSourceOjbect();
 
       public List<Models.OLAssignedApprovals> GetAssignedApprovals()       
       {
           List<Models.OLAssignedApprovals> lPoApproval = new List<Models.OLAssignedApprovals>();
           Models.OLAssignedApprovals li = new Models.OLAssignedApprovals();
 
           DataSet ds = objPOApproval.GetPOApprovals();
 
           foreach (DataRow dr in ds.Tables[0].Rows)
           {
               li = new Models.OLAssignedApprovals();
               li.PoId = Convert.ToInt32(dr["POID"]);
               li.PoStatus = dr["POStatus"].ToString();
 
               lPoApproval.Add(li);
           }
 
 
           return lPoApproval;
       }
   }

Dimiter Madjarov
Telerik team
 answered on 25 Nov 2015
1 answer
96 views

When the user clicks Update the cell in the grid isn't being populated with the EditorTemplate hyperlink value.

EditorTemplate:
@(Html.Kendo().Editor()
.Name("EVIDENCE")
.HtmlAttributes(new { style = "width: 250px;height:25px" })
.Tools(tools => tools.Clear().CreateLink())
.Value(@<text> </text>)
)

view:
<div class="wide-grid">
@Html.AntiForgeryToken()
@(Html.Kendo().Grid(Model.TASKs)
.Name("TasksGrid")
.Columns(columns =>
{
columns.Command(command => { command.Edit(); }).Width(50);
columns.Bound(c => c.STATUS).Visible(false);
columns.ForeignKey(c => c.RESP_ORG_ID, (System.Collections.IEnumerable)ViewData["RespOrgs"], dataFieldText: "RESP_ORG_DESC", dataFieldValue: "RESP_ORG_ID").Title("Resp Org").Width("200px");
columns.ForeignKey(c => c.ACTIVITY_ID, (System.Collections.IEnumerable)ViewData["Activities"], dataFieldText: "ACTIVITY_DESC", dataFieldValue: "ACTIVITY_ID").Title("Activity");
columns.ForeignKey(c => c.SOURCE_DOC_ID, (System.Collections.IEnumerable)ViewData["SourceDocs"], dataFieldText: "SOURCE_DOC_DESC", dataFieldValue: "SOURCE_DOC_ID").Title("Source Doc").ClientTemplate("<a href='#=SOURCE_DOC_PATH#'>#=SOURCE_DOC_DESC#</a>").Width(125);
columns.ForeignKey(c => c.ROLE_ID, (System.Collections.IEnumerable)ViewData["Roles"], dataFieldText: "ROLE_DESC", dataFieldValue: "ROLE_ID").Title("Role");
columns.Bound(c => c.RESP_ORG_ID).Visible(false);
columns.Bound(c => c.ACTIVITY_ID).Visible(false);
columns.Bound(c => c.ROLE_ID).Visible(false);
columns.Bound(c => c.DOC_REF).Width(75);
columns.Bound(c => c.DUE_DATE).EditorTemplateName("DueDate").Width(75);
columns.Bound(c => c.COMPLETED).Width(75);
columns.Bound(c => c.TASK_DESC).EditorTemplateName("TaskDescription").Width(500);
columns.Bound(c => c.EVIDENCE).EditorTemplateName("TaskEvidence").Width(15);
columns.Bound(c => c.CTL_NO);
columns.Bound(c => c.ACQUISITION_ID).Visible(false);
})
.ToolBar(toolbar => toolbar.Create().Text("Add New Task"))
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable()
.Sortable()
.Filterable()
.Groupable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(15)
.ServerOperation(false)
.Events(events => events.RequestEnd("requestEnd"))
.Model(model =>
{
model.Id(a => a.TASK_ID);
})
.Update(update => update.Action("Edit", "Task").Data("sendAntiForgery"))
.Read(read => read.Action("TaskGrid_Read", "Task", new { id = @Model.ACQUISITION_ID }))
.Create(create => create.Action("Create", "Task").Data("sendAntiForgery"))
)
)
</div>

Dimiter Madjarov
Telerik team
 answered on 25 Nov 2015
2 answers
121 views

Hi,

in former WebForm projects I was using asp:DropDownList mostly in these kind of scenarios:

1) The DL was fully rendered server side and the selectable values have been populated using Object/SQL/LinqDataSource on the server.

2) The DL was two-way-bound (by the Bind or Eval statement) to a property of an arbitrary data model, e.g. in the context of a ListView or FormView.

To give you an example of the use case: Say a "status" property in a model need to have values like "On", "Off", "Unknown" and nothing else. An ObjectDataSource ensured, that the DL only contained the values for selection. Then the real model was queried in order to find the selected value and that was selected after Page_Load automatically. Once the user changed the selected value in the "status" DL, the new value was posted back to the server.

That worked fine.

I know how to achieve 1) in the "Kendo World", but I'm wondering, how I could simultaneously "two-way-bind" the DL to another model in order to set the "SelectedItem" form another data model as well as to POST finally changes made by the user.

Any pointer welcome

TIA

Neil
Top achievements
Rank 1
 answered on 24 Nov 2015
2 answers
125 views

I have a custom template for editing a scheduler event. In that template I have a grid to edit an array that is part of my model:

 @(Html.Kendo().Grid<Excent.Apps.Web.Solo.Models.MeetingStudentViewModel>(Model.Students)
                .Name("StudentsGrid")
                .Columns(columns =>
                {
                    columns.Bound(m => m.MeetingStudentID).Hidden();
                    columns.Bound(m => m.FullName).Title("Student");
                    columns.Bound(m => m.Goals);
                })
                .BindTo(Model.Students)
                .DataSource(dataSource => dataSource
                     .Ajax().ServerOperation(false)
                    .Model(model => model.Id(p => p.MeetingStudentID))
                     .Model(model => model.Field(o => o.FullName))
                     .Model(model => model.Field(o => o.Goals))
               )

When I display the template the grid is empty.

Zoran
Top achievements
Rank 1
 answered on 24 Nov 2015
4 answers
71 views

When I popup a recurrence event, it does not go back to the server where I have logic that is based on the start date before current date.

How do I manipulate the Model that it creates from a recurrence event so that I can hide things based on the start date in my custom template?

in my model I have isPassed but this is based on the first in the series and not the current event.. 

 

 

 

Zoran
Top achievements
Rank 1
 answered on 24 Nov 2015
4 answers
143 views

When my page containing a grid control in MVC 5 with Bootstrap is shrunk to below 1024 px. in width, the grid paging control gets distorted as shown in the attached screenshots.

I'm using a scaffolded MVC UI (2015.3.930) grid inside a default _layout body, i.e. it is being inserted inside a div with classes "container body-content" that have not been modified.

I am using customized bootstrap themes that I generated using the Bootstrap theme builder and the Kendo UI theme builder. To the best of my knowledge, I have only altered colors in the custom themes, not anything related to padding or sizing.

Anyone else seen this problems or have suggestions how to proceed or work around this behavior?

Iliana Dyankova
Telerik team
 answered on 24 Nov 2015
Narrow your results
Selected tags
Tags
+? more
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?