You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET MVC中通过select元素提交表单的技术咨询

可正常运行的ASP.NET MVC表单提交示例(含可正常工作的Select元素)

这是一个已经验证过的表单提交实现,能够成功触发指定控制器的操作方法,其中包含的select元素也能被控制器正确获取对应值,完整的视图代码片段如下:

@using (Html.BeginForm("InsertEntry", "Modeliai")) { 
    <div class="row"> 
        <div class="col-7"> 
            <input type="text" class="form-control" placeholder="Pavadinimas" name="Pavadinimas"> 
        </div> 
        <div class="col-3"> 
            <select class="form-control" name="SelectParameterName">
                <!-- 示例选项,可根据实际需求替换 -->
                <option value="option1">选项1</option>
                <option value="option2">选项2</option>
            </select>
        </div>
        <!-- 补充提交按钮,确保表单能正常提交 -->
        <div class="col-2">
            <button type="submit" class="btn btn-primary">提交</button>
        </div>
    </div> 
}

核心要点说明:

  • 表单通过Html.BeginForm()方法明确指定了提交目标:Modeliai控制器下的InsertEntry操作方法
  • 所有表单控件(文本框、select)的name属性需要和控制器方法的参数名保持一致,ASP.NET MVC的模型绑定机制会自动完成值的映射
  • 对应的控制器方法示例如下:
public ActionResult InsertEntry(string Pavadinimas, string SelectParameterName)
{
    // 直接使用接收的表单值进行业务处理
    // 示例逻辑...
    return RedirectToAction("Index");
}

内容的提问来源于stack exchange,提问作者Sprint3rx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:43:51