ASP.NET Core 2.0 Razor Pages Web应用程序单独的Complex BindProperty表单

时间:2018-05-22 05:16:41

标签: c# asp.net razor-pages

我是ASP.NET Core 2.0 Razor Pages Web应用程序框架的新手。问题如下:我需要为复杂的[BindProperty]类创建html表单,并在部分视图或编辑器中分离它的复杂字段(如在MVC中):

public class BasicInformation
{
    // complex filed
    public Name Name { get; set; }

    public string Email { get; set; }

    // collection of objects
    public IEnumerable<Address> Addresses { get; set; }

    //complex field
    public PhoneNumber PhoneNumber { get; set; }

}

我想实现这样的目标:

  <h4>BasicInformation</h4>
<hr />
<div class="row">
    <div class="col-md-4">
        <form method="post">
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <input type="hidden" asp-for="Resume" />

                @Html.EditorFor(m => m.BasicInformation.Name)
            <div class="form-group">
                <label asp-for="BasicInformation.Email" class="control-label"></label>
                <input asp-for="BasicInformation.Email" class="form-control" />
                <span asp-validation-for="BasicInformation.Email" class="text-danger"></span>
            </div>
            <div class="form-group">
                @Html.EditorFor(m => m.BasicInformation.PhoneNumber)
            </div>

           ...
            <div class="form-group">
                <input type="submit" value="Save" class="btn btn-default" />
            </div>
        </form>
    </div>
</div>`

我的页面模型:

 public class BasicInformationFormModel : PageModel
    {
        [BindProperty]
        public BasicInformation BasicInformation { get; set; }

        public IActionResult OnGet()
        {
            return Page();
        }

        public IActionResult OnPost(BasicInformation basicInformation)
        {
            // all data from separate views / editors need to be present in basicInformation
            return Page();
        }
    }

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:1)

您需要创建一个模型类来扭曲com/yongchun/library/view/ImagePreviewFragment references unknown class: com/bumptech/glide/BitmapTypeRequest com/yongchun/library/adapter/ImageFolderAdapter references unknown class: com/bumptech/glide/DrawableRequestBuilder com/yongchun/library/adapter/ImageFolderAdapter references unknown class: com/bumptech/glide/DrawableTypeRequest com/yongchun/library/adapter/ImageListAdapter references unknown class: com/bumptech/glide/DrawableRequestBuilder com/yongchun/library/adapter/ImageListAdapter references unknown class: com/bumptech/glide/DrawableTypeRequest com/yongchun/library/adapter/ImageListAdapter.onBindViewHolder:(Landroid/support/v7/widget/RecyclerView$ViewHolder;I)V references unknown class member: com/bumptech/glide/RequestManager.load:(Ljava/io/File;)Lcom/bumptech/glide/DrawableTypeRequest; com/yongchun/library/view/ImagePreviewFragment.onCreateView:(Landroid/view/LayoutInflater;Landroid/view/ViewGroup;Landroid/os/Bundle;)Landroid/view/View; references unknown class member: com/bumptech/glide/RequestManager.load:(Ljava/io/File;)Lcom/bumptech/glide/DrawableTypeRequest; com/yongchun/library/view/ImagePreviewFragment references unknown class: com/bumptech/glide/DrawableTypeRequest com/yongchun/library/adapter/ImageFolderAdapter.onBindViewHolder:(Lcom/yongchun/library/adapter/ImageFolderAdapter$ViewHolder;I)V references unknown class member: com/bumptech/glide/RequestManager.load:(Ljava/io/File;)Lcom/bumptech/glide/DrawableTypeRequest; com/yongchun/library/view/ImagePreviewFragment$1 references unknown class: com/bumptech/glide/request/animation/GlideAnimation :app:transformClassesWithAndroidGradleClassShrinkerForDebug FAILED :app:buildInfoGeneratorDebug FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:transformClassesWithAndroidGradleClassShrinkerForDebug'. > Warnings found during shrinking, please use -dontwarn or -ignorewarnings to suppress them. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. * Get more help at https://help.gradle.org BUILD FAILED in 1m 19s 模型,

BasicInformation

而不是使用模型public class ProfileViewModel{ public BasicInformation BasicInformation {get;set;} }

将视图设为强类型
ProfileViewModel