gpt4 book ai didi

c# - 如何更改表单在呈现 View 时的操作? (又名通过 ViewBag 或 ViewData)

转载 作者:行者123 更新时间:2023-11-30 22:24:21 25 4
gpt4 key购买 nike

我想通过 ViewBag 或 ViewData 组件指定操作名称以编程方式调用 View 的操作,但我无法这样做。为什么!?

@using (Html.BeginForm(ViewData["SubmitType"], "Person"))
{...

当我运行它时,我得到:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1928: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'BeginForm' and the best extension method overload 'System.Web.Mvc.Html.FormExtensions.BeginForm(System.Web.Mvc.HtmlHelper, string, string)' has some invalid arguments

Source Error:

Line 11: Line 12: Line 13: @using (Html.BeginForm(ViewData["SubmitType"], "Person")) Line 14: { Line 15: @Html.ValidationSummary(true)

最佳答案

糟糕!真不敢相信我忘记了 Viewdata 和 ViewBag 不会保存类型字符串。我必须转换返回值,一切正常!

@using (Html.BeginForm((string)ViewData["SubmitType"], "Person"))
{

关于c# - 如何更改表单在呈现 View 时的操作? (又名通过 ViewBag 或 ViewData),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12812293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com