gpt4 book ai didi

asp.net-mvc - 将 Html.BeginForm 与查询字符串一起使用

转载 作者:行者123 更新时间:2023-12-02 13:25:43 25 4
gpt4 key购买 nike

我的网址如下所示:

customer/login?ReturnUrl=home

在登录 View 中,我使用了这种工作正常的代码模式。

@using(Html.BeginForm())
{
...
}

这会神奇地生成以下 html

<form action="customer/login?ReturnUrl=home" method="post">

但是现在,我需要在表单中添加一个属性(例如 data-id="something" )。我怎样才能做到这一点?如果我没有任何查询字符串,我知道我可以这样做:

@using(Html.BeginForm(action, controller, FormMethod.Post, 
new { data_id="something" }))

但不知道如何添加应该在 html 中的查询字符串:

<form action="customer/login?ReturnUrl=home" method="post" data-id="something">

我考虑过使用<form>直接但不知道如何指定可变的查询字符串。我不知道如何用 Html.BeginForm 来实现它。任何提示将不胜感激。

解决方案:

目前,我使用 <form>带有以下提示 How to get current url value in View 。结果 View 看起来像

<form action="@Request.Url.PathAndQuery" data-id="something" method="POST">

但是如果有一个 BeginForm 的重载方法就好了为此。

最佳答案

这是对我有用的方法

Html.BeginForm("Profile", "Partner", routeValues: new {id=Partner.partner_id},method:FormMethod.Post)

这几乎就像重载方法出现了问题,但通过指定内容,它似乎工作正常......

关于asp.net-mvc - 将 Html.BeginForm 与查询字符串一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7323465/

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