asp.net core - Kendo UI page not binding or referencing to Model at all - Stack Overflow

Must be doing something stupid that Kendo UI failed to bind to Model and I have been getting Nullpointe

Must be doing something stupid that Kendo UI failed to bind to Model and I have been getting Nullpointer Exception System.NullReferenceException: Object reference not set to an instance of an object on the page

Here is the index()

public class MyController : Controller
{
 [HttpGet]
 public IActionResult Index()
 {
   return View(new MyModel { Id=123, Name="Test Name", Description="Test 
 Description"});
 }
}

And here is the Model definition:

namespace MyNamespace.Models
{
    public class MyModel
    {
        public int? Id { get; set; }
        public string? Name { get; set; }
        public string? Description { get; set; }
    }
}

and here is the razor page:

@page
@using MyNamespace.Models
@model MyModel


@if (Model != null && Model.Id != null && Model.Id > 0)
{
    <p>ID: @Model.Id</p>
    <p>Name: @Model.Name</p>
    <p>Description: @Model.Description</p>
}
else
{
    <p>Model ID is null</p>
}

ViewBag properties working fine but cant use strongly typed Model properties

Must be doing something stupid that Kendo UI failed to bind to Model and I have been getting Nullpointer Exception System.NullReferenceException: Object reference not set to an instance of an object on the page

Here is the index()

public class MyController : Controller
{
 [HttpGet]
 public IActionResult Index()
 {
   return View(new MyModel { Id=123, Name="Test Name", Description="Test 
 Description"});
 }
}

And here is the Model definition:

namespace MyNamespace.Models
{
    public class MyModel
    {
        public int? Id { get; set; }
        public string? Name { get; set; }
        public string? Description { get; set; }
    }
}

and here is the razor page:

@page
@using MyNamespace.Models
@model MyModel


@if (Model != null && Model.Id != null && Model.Id > 0)
{
    <p>ID: @Model.Id</p>
    <p>Name: @Model.Name</p>
    <p>Description: @Model.Description</p>
}
else
{
    <p>Model ID is null</p>
}

ViewBag properties working fine but cant use strongly typed Model properties

Share Improve this question edited Nov 18, 2024 at 22:05 Desichele asked Nov 18, 2024 at 20:00 DesicheleDesichele 3992 gold badges6 silver badges15 bronze badges 4
  • how do you use the kendo-ui. I didn't see anythingwrong with these codes. – Qiang Fu Commented Nov 20, 2024 at 7:19
  • you mean using Kendo.Mvc & using Kendo.Mvc.UI on top of the page.. yeah I do have that still have been getting null pointer exception – Desichele Commented Nov 20, 2024 at 20:37
  • @(Html.Kendo().TextAreaFor(m=>m.Description)), for example, should generate a TextArea component for the description. However there is something odd - there is a controller that is indicating a view should be loaded, but also a @page directive indicating the use of RazorPages, so which on is it - an MVC view or a RazorPage - that you are using? Does the page model define an instance of MyModel? – Aleksandar Commented Nov 25, 2024 at 14:44
  • 1 Thanks for pointing to the right direction. the culprit was the @page directive at the top of the page. this was supposed to be MVC and not a razor page. Thanks a bunch Aleksandar – Desichele Commented Nov 25, 2024 at 21:57
Add a comment  | 

1 Answer 1

Reset to default 0

Resolved (thanks for pointing to right direction). The culprit was the @page directive at the top of the page. This was supposed to be MVC and not a Razor page. Copied the last comment by Aleksandar below:

@(Html.Kendo().TextAreaFor(m=>m.Description)), for example, should generate a TextArea component for the description. However there is something odd - there is a controller that is indicating a view should be loaded, but also a @page directive indicating the use of RazorPages, so which on is it - an MVC view or a RazorPage - that you are using? Does the page model define an instance of MyModel?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745597306a4635193.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信