Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

组件提交表单,服务端验证失败时还原页面并显示ModelState的错误信息 #406

Closed
SeriaWei opened this issue Dec 29, 2020 · 0 comments

Comments

@SeriaWei
Copy link
Owner

SeriaWei commented Dec 29, 2020

How to use

Include @Html.HiddenForCurrentPagePath() to your form

<form method="post">
      @Html.HiddenForCurrentPagePath()
...
</form>

Use RenderRefererPageAttribute on your action

[HttpPost, RenderRefererPage]
public IActionResult Submit(MessageEntity entity)
{
    if (ModelState.IsValid)
    {
        ....
    }
    return View(entity);
}

Get model from widget service WidgetDisplayContext.Model:

public override WidgetViewModelPart Display(WidgetDisplayContext widgetDisplayContext)
{
    if (widgetDisplayContext.Model is MessageEntity messageEntity)
    {
        return widgetDisplayContext.ToWidgetViewModelPart(messageEntity);
    }

    return widgetDisplayContext.ToWidgetViewModelPart(new MessageEntity());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant