在MVC中传递Dropdownlist选定值(从视图到控制器) [英] Pass Dropdownlist Selected Value In MVC(From View To Controller)

查看:320
本文介绍了在MVC中传递Dropdownlist选定值(从视图到控制器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在视图中将下拉列表选定值从视图传递到控制器....

How To Pass Dropdownlist Selected Value from View To Controller in mvc....

推荐答案

如果将模型绑定到视图,您将直接获取所选值控制器



(没有绑定模型我们也可以从ajax命中达到所选值)



1 。我很少有东西你把任何模型绑定到你的下拉列表的视图。?



2.你是否在控制器中写了post action方法?





//在视图中

if you bind model to view you will get the selected value directly in controller

(without binding the model also we can achieve the selected value from ajax hit)

1.tell me few things have you bind any model to the view in which your dropdown exist.?

2. did you write post action method in controller?


//in view
<% using (Html.BeginForm())
               { %>
            
            <%=Html.DropDownListFor(m => m.CourseId, new SelectList((ViewBag.Courses) as SelectList, "Value", "Text"), "Select")%>
            
            <input id="submit" type="button" value="Save" name="submit" />
            <%} %>



//在document.ready


//in document.ready


(#submit)。live(click,function(e){

e.preventDefault();
var data = JSON.stringify( {CourseId:
("#submit").live("click", function (e) { e.preventDefault(); var data = JSON.stringify({ CourseId:


('#CourseId')。val()});
('#CourseId').val()});


这篇关于在MVC中传递Dropdownlist选定值(从视图到控制器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆