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

EditorFor() - Object reference not set to an instance of an object.

5 Answers 178 Views
Editor
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Justin
Top achievements
Rank 1
Justin asked on 29 Oct 2010, 10:32 PM
I just installed the Telerik extensions for MVC and I'm trying to get a simple Editor set up that will hold a Biography.

This doesn't work... Throws the following:

Object reference not set to an instance of an object.


<%: Html.LabelFor(model => model.BioText) %>
<%: Html.Telerik().EditorFor(model => model.BioText) %>
<%: Html.ValidationMessageFor(model => model.BioText) %>

But without any other changes, this does work...

<%: Html.LabelFor(model => model.BioText) %>
<%: Html.TextAreaFor(model => model.BioText) %>
<%: Html.ValidationMessageFor(model => model.BioText) %>

What would cause this?

5 Answers, 1 is accepted

Sort by
0
Justin
Top achievements
Rank 1
answered on 29 Oct 2010, 10:56 PM
Does EditorFor() only work when you are passing existing data? This editor is on a 'Create' page.
0
Accepted
Hristo Germanov
Telerik team
answered on 01 Nov 2010, 04:32 PM
Hi Justin,

Thank you for your feedback. This is a bug and it will be fixed with the next release in the middle of November.

I have update your Telerik points.

The workaround for this issue is:
1. Replace EditorFor method in ViewComponentFactory with this method:
public virtual EditorBuilder EditorFor(Expression<Func<TModel, string>> expression)
{
      Guard.IsNotNull(expression, "expression");
      return Editor()
          .Name(GetName(expression))
          .Value((string)ModelMetadata.FromLambdaExpression(expression, HtmlHelper.ViewData).Model);
}
2. Rebuild the source project. Make sure the build configuration is set to Release MVC2 NET35 if you are using ASP.NET MVC 2.


Best wishes,
Hristo Germanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Justin
Top achievements
Rank 1
answered on 01 Nov 2010, 07:08 PM
Alright, thanks a lot! I will make that fix.

I was able to work around it by simply naming the editor:

<% Html.Telerik().Editor()Name("BioText").Value(()=>
                       {
                           %>
                               <strong>Enter Biography Here</strong>
                           <%
                       }).Render();
                %>
0
Mohammad
Top achievements
Rank 1
answered on 02 Nov 2010, 10:57 AM
Hi Hristo
I replaced EditorFor method in ViewComponentFactory with the mothed you have given and built the project, as well copyed the Telerik.Web.Mvc\bin\Debug MVC2 NET35\Telerik.Web.Mvc.dll  file to my project but still getting the error "This property cannot be set to a null value"
but I am trying to get the editor and apply it to this design
http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx
<% for (int i = 0; i < 3; i++) { %>

  <%: Html.TextBoxFor(m => m[i].Title) %> //works fine
  <%: Html.Telerik().EditorFor(m => m[i].Author) %> set the Author to null
  <%: Html.TextBoxFor(m => m[i].DatePublished) %>  //works fine

<% } %>
0
Avdut
Top achievements
Rank 1
answered on 02 Nov 2010, 05:43 PM
<% Html.Telerik().Editor()Name("BioText").Value(()=>
                       {
                           %>
                               how to pass data dynamically here
                           <%
                       }).Render();
                %>

I am passing the data in <%= HttpUtility.HtmlEncode(ViewData["Description"].ToString())%> but it is not showing Properly

Its showing as follow
Old Style Cubs LED Neon 09 Version&amp;nbsp;&lt;BR&gt;
&lt;BR&gt;
&lt;P style=&quot;MARGIN: 0in 0in 10pt&quot;&gt;&lt;SPAN style=&quot;LINE-HEIGHT: 115%; FONT-FAMILY: &#39;Arial&#39;,&#39;sans-serif&#39;; COLOR: blue; FONT-SIZE: 8.5pt&quot;&gt;**Due to the shipment requirements of this product, it will not ship via UPS or FedEx and will be sent via Truck-line.&amp;nbsp;&amp;nbsp;Your online shipping estimate may not reflect the correct amount for this product, however you will be billed the actual shipping costs.&amp;nbsp; Other items in your order may ship together to save/expedite shipping.**&lt;/SPAN&gt;&lt;/P&gt;
Please order by Individual Pieces.


But if I paste the above in value of editor its shows properly
what is the problem ...............please put some light on this issue






Tags
Editor
Asked by
Justin
Top achievements
Rank 1
Answers by
Justin
Top achievements
Rank 1
Hristo Germanov
Telerik team
Mohammad
Top achievements
Rank 1
Avdut
Top achievements
Rank 1
Share this question
or