dotnet / dotnet/aspnetcore

server-side model validation - error message in partial view

Open
#28,364 1 comment 0 reactions 0 assignees View on GitHub
area-mvc feature-model-binding investigate
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Describe the bug
Hello, I have a complex model object that I want to create a form for using tag helpers. I want to implement some parts of the form in partial views for nested object properties of the model.

```
public class Parent
{
[Required]
public string name { get; set; }
public Child child { get; set; }
}

public class Child
{
[Required]
public string description { get; set; }
}
```

```
@model Parent







Submit

```

```
@model Child






```

I use `name="child.description"` for the input to make model binding work correctly. I also added `data-valmsg-for="child.description"` to make the validation message to work correctly. All of these work fine when using jquery-validation and jquery-validation-unobtrusive. But when using server-side validation the validation messages for the partial view are not showing.

If I make partial view use the same model as main view and then use `asp-for="child.description"` and `asp-validation-for="child.description"`.

Is this a bug or am I missing something obvious here?
Kind regards, Dimitris.

### To Reproduce
Check the zip attachment for a minimalistic repro

[ValidationMessage.zip](https://github.com/dotnet/aspnetcore/files/5638843/ValidationMessage.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.