繁体   English   中英

无法在剃刀页面中将模型值分配给参数

[英]Not able to assign model value to a parameter in razor pages

我有一个剃刀页面代码,用于显示页面。

public class RegisterModel : PageModel
{

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

    public string Test {get; set;}
    public class InputModel
    {        
        public List<SelectListItem> QList { get; set; }
    }

    public void OnGet()
    {
        Helper helper = new Helper(_logger, _context);
        var Test = helper.GetTestString();
        var saltyList = helper.GetAllApples();

        Input.QList = saltyList;
    }
}

变量saltyList具有15个值。 但是我遇到一个错误:

{System.ExecutionEngineException:引发了类型为'System.ExecutionEngineException'的异常。}

我想念什么吗? 无法在Get方法中分配值还是我遗漏了什么?是否存在在分配值之前没有将Input.Qlist初始化为任何东西的问题? 测试工作正常,但InputModel分配却没有。

您需要在OnGet方法中分配Input的值。 像这样的东西:

public void OnGet()
{
    Helper helper = new Helper(_logger, _context);
    var Test = helper.GetTestString();
    var saltyList = helper.GetAllApples();

    Input = new InputModel
            {   
                QuestionList = questionList
            };
}

如果要像执行操作一样绑定Get中的值,则可能必须对Bindproperty使用SupportGet = true。

[BindProperty(SupportGet=true)]
public InputModel Input { get; set; }

您可以在这里了解更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM