Skip to main content

An extension with 'X' name already rendered

  • 2 minutes to read

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