All docs
V20.2
20.2
20.1
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

MVC-Specific Server-Side Issues

  • 6 minutes to read

The links below describe how to solve MVC-specific server-side issues:

Why redirect to another page or View does not work on AJAX requests

Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery, DbRawSqlQuery) is not supported

An alert message with the HTML/JavaScript/CSS content appears when you use callback-aware extensions

An extension with 'X' name is already rendered

'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'DevExpress'

Why redirect to another page or View does not work on AJAX requests

This error occurs when you redirect to another page on AJAX requests ( $.ajax()) on the server. For example, when you call the Redirect method in an action method that handles AJAX requests in a controller.

In this case, return to the initial View and then use JavaScript to redirect to another page.

Controller:

return Json(new { newUrl = "https://www.devexpress.com" });  

View:

$.post('@Url.Action("Save")',  
    function (data) {  
        if(data.newUrl)  
            window.location.href = data.newUrl;  
    }  
);  

Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery, DbRawSqlQuery) is not supported

Error Description:

This error can occur when you use the Bind method with the non-evaluated / IQueryable Model (for example, a table from a data context) to bind a data-aware DevExpress MVC Extensions (grid-like, scheduler and tree list extensions) to data.

Controller:

public ActionResult GridViewPartial() {  
    EFDataContext db = new EFDataContext();  
    return PartialView(db.Table_Name);  
}  
Public Function GridViewPartial() As ActionResult  
    Dim db As New EFDataContext()  
    Return PartialView(db.Table_Name)  
End Function  

PartialView:

@Html.DevExpress().GridView(settings => {  
    ...  
}).Bind(Model).GetHtml()  
@Html.DevExpress().GridView( _  
    Sub(settings)  
    ...  
End Sub).Bind(Model).GetHtml()  

Solution:

To resolve this issue, you can use the ToList method to load/evaluate a Model.

Controller:

using System.Linq;  
...  
public ActionResult GridViewPartial() {  
    EFDataContext db = new EFDataContext();  
    return PartialView(db.Table_Name.ToList());  
}  
Imports System.Linq  
...  

Public Function GridViewPartial() As ActionResult  
    Dim db As New EFDataContext()  
    Return PartialView(db.Table_Name.ToList())  
End Function  

See Also:

Alert message with the HTML/JavaScript/CSS content appears when you use callback-aware extensions

Solution:

Do the following to solve the issue:

  • The SettingsBase.Name property value should be the same between callbacks.

  • Define extensions in a separate PartialView file without additional tags (for example, HTML markup, scripts).

  • Use the Html.Partial, Html.RenderPartial expression/code block or the Html.Action, Html.RenderAction that return the PartialViewResult to render the PartialView.

  • The action method (CallbackRouteValues.Action) should return the same PartialViewResult that contains the callback-aware extensions.

An extension with 'X' name already rendered

Error Description:

The error occurs when several DevExpress MVC Extension (for example, TextBox) have the same SettingsBase.Name property value.

PartialView:

@Html.DevExpress().TextBox(settings => {  
    settings.Name = "TextBox";  
}).GetHtml()  

View:

@Html.Partial("EditorsPartial")  
@Html.Partial("EditorsPartial")  

Solution:

An extension's Name property should be unique to avoid conflicts between extensions in the same view.

  1. Pass a custom "index" value as a parameter to the Html.Partial / Html.Action helper method.

  2. Retrieve the custom value in the Controller / PartialView.

  3. Use the ViewData to pass the custom value to the PartialView.

  4. Use the custom value in the PartialView as a part of the SettingsBase.Name property.

Controller:

public ActionResult EditorsPartial(int part) {  
    ViewData["part"] = part;  
    return View();  
}  
Public Function EditorsPartial(ByVal part As Integer) As ActionResult  
    ViewData("part") = part  
    Return View()  
End Function  

PartialView:

@Html.DevExpress().TextBox(settings => {  
    settings.Name = "TextBox" + ViewData["part"];  
}).GetHtml()  
@Html.DevExpress().TextBox( _  
    Sub(settings)  
            settings.Name = "TextBox" + ViewData("part").ToString()  
    End Sub).GetHtml()  

View:

@Html.Partial("EditorsPartial", new ViewDataDictionary(this.ViewData) { { "part", 1 } })  
@Html.Partial("EditorsPartial", new ViewDataDictionary(this.ViewData) { { "part", 2 } })  

@for (int i = 3; i < 5; i++) {  
    Html.RenderPartial("EditorsPartial", new ViewDataDictionary(this.ViewData) { { "part", i } });  
}  

@* Actions rendering *@  

@Html.Action("EditorsPartial", new { part = 5 })  
@Html.Action("EditorsPartial", new { part = 6 })  

@for (int i = 7; i < 9; i++) {  
    Html.RenderAction("EditorsPartial", new { part = i });  
}  

@* Template rendering *@  

...  
settings.Columns.Add(column => {  
    column.SetDataItemTemplateContent(c => {  
        Html.DevExpress().HyperLink(hl => {  
            hl.Name = "hlNew_" + c.KeyValue.ToString();  
            ...  
        }).Render();  
        ...  
@* Immediate views rendering *@  

@Html.Partial("EditorsPartial", New ViewDataDictionary(Me.ViewData) From {{"part", 1}})  
@Html.Partial("EditorsPartial", New ViewDataDictionary(Me.ViewData) From {{"part", 2}})  

@For i = 3 To 4  
    Html.RenderPartial("EditorsPartial", New ViewDataDictionary(Me.ViewData) From {{"part", i}})  
Next  

@* Actions rendering *@  

@Html.Action("EditorsPartial", New With {.part = 5})  
@Html.Action("EditorsPartial", New With {.part = 6})  

@For i = 7 To 8  
    Html.RenderAction("EditorsPartial", New With {.part = i})  
Next  

@* Template rendering *@  
            ...  
            settings.Columns.Add( _  
                Sub(column)  
                        column.SetDataItemTemplateContent( _  
                            Sub(c)  
                                    Html.DevExpress().HyperLink( _  
                                        Sub(hl)  
                                                hl.Name = "hlNew_" + c.KeyValue.ToString()  
                                                ...  
                                        End Sub).Render()  
                                        ...  

See Also: How to emulate the Command Column with a data column DataItemTemplate

'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'DevExpress'

This error can occur in the following cases:

  • ASP.NET MVC 3 projects are upgraded to ASP.NET MVC 4 (or ASP.NET MVC 4 projects to ASP.NET MVC 5)

    Configure the "appSettings" and "assemblies" sections.

    MVC 3 to MVC 4:

    <appSettings>  
        <add key="webpages:Version" value="2.0.0.0" />  
        ...  
    </appSettings>  
    <system.web>  
        <compilation ...>  
            <assemblies>  
                ...  
                <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />  
                <add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />  
                <add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />  
            </assemblies>  
        </compilation>  
    </system.web>  
    

    See Also: Upgrading an ASP.NET MVC 3 Project to ASP.NET MVC 4

    MVC 4 to MVC 5:

    Follow steps listed in the following MSDN topic: How to Upgrade an ASP.NET MVC 4 and Web API Project to ASP.NET MVC 5 and Web API 2

  • Areas are used.

    Copy DevExpress namespaces from the ~/Views/Web.config configuration file to ~/Areas/AREA_NAME/Web.config configuration file.

    For ASP.NET MVC 4:

    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />  
    

    For ASP.NET MVC 3:

    ~/Areas/AREA_NAME/Web.config:

    <system.web.webPages.razor>  
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />  
        <pages pageBaseType="System.Web.Mvc.WebViewPage">  
            <namespaces>  
                <add namespace="System.Web.Mvc" />  
                <add namespace="System.Web.Mvc.Ajax" />  
                <add namespace="System.Web.Mvc.Html" />  
                <add namespace="System.Web.Routing" />  
                <add namespace="DevExpress.Utils" />  
                <add namespace="DevExpress.Web.ASPxClasses" />  
                <add namespace="DevExpress.Web.ASPxGridView" />  
                <add namespace="DevExpress.Web.ASPxGridView.Export" />  
                <add namespace="DevExpress.Web.ASPxEditors" />  
                <add namespace="DevExpress.Web.ASPxCallbackPanel" />  
                <add namespace="DevExpress.Web.ASPxMenu" />  
                <add namespace="DevExpress.Web.ASPxNavBar" />  
                <add namespace="DevExpress.Web.ASPxPopupControl" />  
                <add namespace="DevExpress.Web.ASPxRoundPanel" />  
                <add namespace="DevExpress.Web.ASPxSplitter" />  
                <add namespace="DevExpress.Web.ASPxTabControl" />  
                <add namespace="DevExpress.Web.ASPxTreeView" />  
                <add namespace="DevExpress.Web.ASPxUploadControl" />  
                <add namespace="DevExpress.Web.ASPxHtmlEditor" />  
                <add namespace="DevExpress.Web.ASPxSpellChecker" />  
                <add namespace="DevExpress.XtraCharts" />  
                <add namespace="DevExpress.XtraCharts.Web" />  
                <add namespace="DevExpress.XtraReports" />  
                <add namespace="DevExpress.XtraReports.UI" />  
                <add namespace="DevExpress.XtraReports.Web" />  
                <add namespace="DevExpress.XtraPivotGrid" />  
                <add namespace="DevExpress.Data.PivotGrid" />  
                <add namespace="DevExpress.Web.ASPxPivotGrid" />  
                <add namespace="DevExpress.Web.ASPxPivotGrid.Export" />  
                <add namespace="DevExpress.Web.Mvc" />  
                <add namespace="DevExpress.Web.Mvc.UI" />  
                <add namespace="DevExpress.XtraScheduler" />  
                <add namespace="DevExpress.XtraScheduler.Native" />  
                <add namespace="DevExpress.Web.ASPxScheduler" />  
            </namespaces>  
        </pages>  
    </system.web.webPages.razor>  
    

    See Also: How to use DevExpress MVC Extensions in the ASP.NET MVC Areas