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

[Solved] Slider as Editor requires 'Static' Name

1 Answer 15 Views
Slider
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sander
Top achievements
Rank 1
Sander asked on 21 May 2011, 10:32 AM
Hello,

I like the Telerik slider for it's simplicity.

So now I try to use the Slider as an Editor:

<%

 

@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<int?>" %>

 

 

<%

 

= Html.Telerik().Slider<int>()

 

 

 

 

.HtmlAttributes(new { style = "width:100" })

 

 

.Min(0)

 

.Max(10)

 

.ShowButtons(

 

true)

 

 

.Value(Model)

 

%>

But when I run this, I get a runtime exception:

System.ArgumentException was unhandled by user code
  Message=Value cannot be null or empty.
Parameter name: expression
  Source=System.Web.Mvc
  ParamName=expression
  StackTrace:
       at System.Web.Mvc.ViewDataDictionary.GetViewDataInfo(String expression)
       at System.Web.Mvc.ViewDataDictionary.Eval(String expression)
       at Telerik.Web.Mvc.UI.InputComponentExtensions.GetValue[T](IInputComponent`1 instance, Func`2 converter)
       at Telerik.Web.Mvc.UI.Slider`1.WriteHtml(HtmlTextWriter writer)
       at Telerik.Web.Mvc.UI.ViewComponentBase.ToHtmlString()
       at Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.ToHtmlString()
       at Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.ToString()
       at System.IO.TextWriter.Write(Object value)
       at System.Web.Mvc.ViewPage.SwitchWriter.Write(Object value)
       at System.Web.UI.HtmlTextWriter.Write(Object value)
       at ASP.views_shared_editortemplates_slider_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\Data\Semac\Development\FeasibilityStudy\SmartEnergySemacClient\MvcApplication2\MvcApplication2\Views\Shared\EditorTemplates\Slider.ascx:line 2
       at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
       at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
       at System.Web.UI.Control.Render(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
       at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
       at System.Web.UI.Page.Render(HtmlTextWriter writer)
       at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:


But when i add a static name (same name as the property in the viewmodel) to the editor:

.Name("MySliderField")

the slider works fine.

My issues with this are:
 - adding a static name forces me to use this name (MySliderField) in each viewmodel
 - there can only be one slider on each viewmodel (property names are unique in a class in C#)
 - other editors like the IntegerTextBox do not require a static name
 
Is there a fix for this?

 

1 Answer, 1 is accepted

Sort by
0
Sander
Top achievements
Rank 1
answered on 21 May 2011, 12:35 PM
Found it.

I used the more generic Name found on other editors and now it works fine.

 

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<int?>" %>
<%= Html.Telerik().Slider<int>()
        .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
        .HtmlAttributes(new { style = "width:100" })
        .Min(0)
        .Max(10)
        .ShowButtons(true)
        .Value(Model)
%>
Tags
Slider
Asked by
Sander
Top achievements
Rank 1
Answers by
Sander
Top achievements
Rank 1
Share this question
or