Моя страница страницы модели бритвы Core продолжает выдавать исключения и не будет отображаться - PullRequest
0 голосов
/ 27 марта 2019

Просто пытаюсь создать простую страницу бритвы с помощью Pagemodel.Что бы я ни делал, это исключение.В режиме редактирования кажется, что intellsense видит его, но при попытке запустить модель становится нулевой.Я пробовал разрывы кода, сравнивая их с другими страницами, учебными пособиями и т. Д. Независимо от того, что я получаю:

исключение "viewdata null"

Страница

@page
@model TransitSection15.Areas.GTFS.Views.Home.FileSet_NewModel.InputModel
@{
}

<h4>Create a GTFS File Set</h4>
<h1>Add ddd</h1>
@if (ViewBag.Data == null)
{
    @Html.Raw("No data!")
}

@if  (String.IsNullOrEmpty(@Model.Name))
{
string what = "what";
}

<div class="row">
<div class="col-md-4">
    <form method="post">
        <h4>Create a new File Set</h4>
        <div asp-validation-summary="All" class="text-danger"></div>
        <div class="form-group">
            <label asp-for="Name" class="control-label"></label>

Код

public class FileSet_NewModel : PageModel
{
    private readonly UserManager<ApplicationUser> _userManager;
    private readonly ILogger<FileSet_NewModel> _logger;

    public FileSet_NewModel(
            UserManager<ApplicationUser> userManager,
            ILogger<FileSet_NewModel> logger)
    {
        _userManager = userManager;
        _logger = logger;
    }


    [BindProperty]
    public InputModel Input { get; set; }

    public string ReturnUrl { get; set; }

    public string MyHeader { get; set; }

    public class InputModel 
    {
        [Required]
        //[StringLength(120, ErrorMessage = "Name cannot be longer than 
     120 characters.")]
        [Display(Name = "Name")]
        public string Name { get; set; }

        [Required]
        [StringLength(512, ErrorMessage = "Descriptione cannot be longer 
  than 512 characters.")]
        [Display(Name = "Description")]
        public string Description { get; set; } = "Description";

        [Required]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", 
             ApplyFormatInEditMode = true)]
        public DateTime CalendarStartDate { get; set; }

        [Required]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", 
         ApplyFormatInEditMode = true)]
        public DateTime CalendarEndDate { get; set; }
    }


    public void OnGet()
    {
        // ReturnUrl = returnUrl;
         ReturnUrl = "~/index";
    }

    public async Task<IActionResult> OnPostAsync(string returnUrl = null)
    {
        returnUrl = returnUrl ?? Url.Content("~/");
        if (ModelState.IsValid)
        {
            if (String.IsNullOrEmpty(Input.Name))
                Input.Name = String.Empty;

            if (String.IsNullOrEmpty(Input.Description))
                Input.Description = String.Empty;

            if (Input.CalendarStartDate == null )
                Input.CalendarStartDate = DateTime.MinValue;

            if (Input.CalendarEndDate == null)
                Input.CalendarEndDate = DateTime.MaxValue;

            var NewSet = new GTFSFileSet
            {
                Name = Input.Name,
                Description = Input.Description,
                CalendarStartDate = Input.CalendarStartDate,
                CalendarEndDate = Input.CalendarEndDate,
                Active = true,
                SetValid = false,
                CreatedBy = "Steve",
                CreationDate = DateTime.Now        
            };



            /////////////////////////////////
            //do the Save Here
            //
            //GTFSFileSet.Add(NewSet);
          //  await _db.SaveChangesAsync();
          //  return RedirectToPage("/Index");

            var result = false;
            //if (result.Succeeded)
            if (result)
            {
                _logger.LogInformation("User created a new FileSet.");


                //var callbackUrl = Url.Page(
                //    "/Account/ConfirmEmail",
                //    pageHandler: null,
                //    values: new { userId = user.Id, code = code },
                //    protocol: Request.Scheme);


                return LocalRedirect(returnUrl);
            }
            //foreach (var error in result.Errors)
            //{
            //    ModelState.AddModelError(string.Empty, 
       error.Description);
            //}
        }

        // If we got this far, something failed, redisplay form
        return Page();
    }
}
...