Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net tag helpers not working

Asp.net tag helpers not worked in my project.

I add this code to project.json

"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",

in _ViewImports.cshtml i add

@using Homebank
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"

When in view i use asp.net tag helpers - page not return data;

@model Homebank.Models.Admins

@{
    ViewData["Title"] = "Create";
}
 <input asp-for="Email" class="form-control" />

Not errors, not exceptions. White page enter image description here

like image 579
user1088259 Avatar asked Oct 19 '22 13:10

user1088259


1 Answers

Make sure your class has the property

Your tag helper is trying to access Homebank.Models.Admins.Email. Make sure that class has an Email property.

namespace Homebank.Models
{
    public class Admins
    {
        public string Email { get; set; }
    }
}

I think that is the most likely fix, because your code works when you remove the Email tag helper. Here are some other ideas, though.

Add a detailed error page

Instead of a white screen, we can receive a detailed error page. Add the following line of code to the Configure method.

public void Configure(IApplicationBuilder app)
{
    // other code omitted for clarity
    app.UseDeveloperExceptionPage();
    app.UseMvc();
}

That will provide more debugging information. E.g.

An error occurred during the compilation of a resource...

Restore your packages

It might be that you need to restore the Microsoft.AspNet.Mvc.TagHelpers package. Here is how from the command line:

dnu restore
dnu build
dnx web

This is an unlikely fix, because your code runs when you comment out the Email tag helper, even though you're using tag helpers in the _ViewImports.cshtml page.

like image 95
Shaun Luttin Avatar answered Oct 29 '22 22:10

Shaun Luttin