Skip to content

Enable BindNever or BindingBehavior(BindingBehavior.Never) for Blazor WebAssembly Shared Project(Model) #42736

@hamiddd1980

Description

@hamiddd1980

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I have implemented a Single Page Application using Blazor WebAssembly. the solution contains three projects:
1-Server Side Web Api : MySolution.Server
2-Client Side Blazor WebAssembly: MySolution.Client
3-Shared Project contains EF Core Models:MySolution.Shared
I use this EF Core Models in my Presentation and Model Binding Directly.
let say we have a simple model named Person :

public class Person
{
        [BindNever] // doesn't work in Blazor Shared Project and Produces Error
        public int Id{ get; set;}
        public string LastName{get; set;}
        public string Name{get; set;}
}

in My Web Api Controller, I want to prevent Model Binding for my EF Core Properties :Id and Name:

public IActionResult CreateNew(Person person)   // [Bind(Exclude("Id"))] is not implemented in DotNetCore
{
      if(ModelState.IsValid)
      {
           //Do Other Works
      }
}

The Problem:

1-You are not Allowed to use BindNever or BindingBehavior(BindingBehavior.Never) for Models Properties in Shared Project.
2-The Exclude property is removed from BindAttribute class in Dotnet. So I can not use following code in my Web Api:
public IActionResult CreateNew([Bind(Exclude("Id"))]Person person) // Not Available
Request:
How Can I Exclude Some Properties from Model Binding for Classes that are defined in Blazor Shared Project?

Describe the solution you'd like

Like past, please add support for BindNever or Bind(Exclude) (or something like that) for Models that are defined in Blazor Shared Project.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor Componentsfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssemblyquestion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions