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

[Solved] NumericTextBoxFor throws NullReferenceException

4 Answers 138 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paul
Top achievements
Rank 1
Paul asked on 31 Aug 2010, 02:58 AM
Here is my Index.aspx view code:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<TelerikMvcApplication1.Models.Customer>" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
Numeric Control (data bound):
<%: Html.Telerik().NumericTextBoxFor(model => model.CardNumber) %>
</asp:Content>

Here is my Controller code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telerik.Web.Mvc;
 
using TelerikMvcApplication1.Models;
 
namespace TelerikMvcApplication1.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            Customer customer = new Customer();
            return View(customer);
        }
    }
}

Here is the Customer Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
 
namespace TelerikMvcApplication1.Models
{
    public class Customer
    {
        [DisplayName("Card #")]
        public long? CardNumber { get; set; }
    }
}

So what am I doing wrong to databind my model to the NumericTextBox?

Thanks,
Paul

4 Answers, 1 is accepted

Sort by
0
Hristo Germanov
Telerik team
answered on 31 Aug 2010, 04:12 PM
Hi Paul,

Thank you for reporting this issue.

I confirm that it is a bug, which will be fixed with next official release of Telerik Components for ASP.NET MVC.

Attached is the patched file. Replace the existing one in the source code distribution and rebuild the source project. Make sure the build configuration is set to Release MVC2 NET35 if you are using ASP.NET MVC 2.

I have updated your Telerik points.

All the best,
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
Paul
Top achievements
Rank 1
answered on 07 Sep 2010, 09:58 PM
Thanks for this response Hristo but I'm not sure how I should apply this fix to my current version of the controls.  I realize you just included a .cs file but I'm not currently using the source code to build my controls.  I did some digging and found the source code was uploaded to your codeplex site (http://telerikaspnetmvc.codeplex.com/) but I notice the code on that site is using VS2008 solution.  I converted that solution to vs2010 (since I haven't installed vs2008 on my new laptop yet) but it will not build now.  It doesn't give me any errors when building it just says "Build Failed" no matter what configuration I use.

If I should post this question on the discussion forums on the codeplex site please let me know but I assumed you could help me since you have done such a good job so far.

Thanks,
Paul
0
Accepted
Hristo Germanov
Telerik team
answered on 08 Sep 2010, 12:09 PM
Hello Paul,

Attached is the modified official version of Telerik ASP.NET MVC.

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
Chris
Top achievements
Rank 1
answered on 02 Oct 2010, 01:08 AM

Hristo,

I compiled in the ViewComponentFactory from the .rar file in 2010.2.825 source.  Now it doesn't cause the null pointer exception, instead it renders the output as encoded html.  I've attached a zip file with the html output as it shows incorrectly in the browser.

But here is the page code...

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Page.Master" Inherits="System.Web.Mvc.ViewPage<JournalModel>" %>
  
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Test
</asp:Content>
  
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
  
    <h2>Test</h2>
  
    <h2>[[<%: Model.Date %>]]</h2>
  
    <%: Html.Telerik().NumericTextBoxFor(model=>model.Date2).Name("Date").MinValue(0).MaxValue(40) %>
    <%: Html.Telerik().NumericTextBox().Name("dsfsdf") %>
  
</asp:Content>

So there is still an issue. 

Oh running IE8 (32-bit) on Windows 7 64-bit with VS2010, .NET 4.0 and MV2.


As an update I switched to using

<%= Html.Telerik().NumericTextBoxFor(model=>model.Date2).Name("Date").MinValue(0).MaxValue(40) %>

And it displayed unescaped html.  Not sure why when using "<%:" the NumericTextBoxFor method is displaying incorrectly.  As Date2 is a byte, I tested the following:

<%= Html.Telerik().NumericTextBox<byte>().Name("dsfsdf") %>

And that worked successfully.  In the case of NumericTextBoxFor and NumericTextBox<byte> they both use the "Telerik.Web.Mvc.UI.TextboxBaseHtmlBuilderFactory<byte>" renderer factory.  And the ToHtmlString() output is identical for both

{<div class="t-widget t-numerictextbox" id="Date"><input class="t-input" id="Date-input" name="Date" title="Date" value="0" /><a class="t-link t-icon t-arrow-up" href="#" tabindex="-1" title="Increase value">Increment</a><a class="t-link t-icon t-arrow-down" href="#" tabindex="-1" title="Decrease value">Decrement</a></div>}
  
{<div class="t-widget t-numerictextbox" id="dsfsdf"><input class="t-input" id="dsfsdf-input" name="dsfsdf" title="dsfsdf" value="" /><a class="t-link t-icon t-arrow-up" href="#" tabindex="-1" title="Increase value">Increment</a><a class="t-link t-icon t-arrow-down" href="#" tabindex="-1" title="Decrease value">Decrement</a></div>}

So basically switching to the "<%=" rather than the "<%:", which escapes, seems to work with the updated ViewComponentFactory class.  (Note that Scott Guthrie in his blog, http://weblogs.asp.net/scottgu/archive/2010/01/10/asp-net-mvc-2-strongly-typed-html-helpers.aspx, is using "<%=" for the strongly typed Html Helpers).

Tags
NumericTextBox
Asked by
Paul
Top achievements
Rank 1
Answers by
Hristo Germanov
Telerik team
Paul
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Share this question
or