你不能
MessageBox.Show
在ASP.NET MVC中,它用于
winform
.
集合
id='SelectedFileName'
OnChange
事件。使用JS
alert
功能
你可以用JS来完成。
这是jquery示例。
$('#SelectedFileName').change(function(){
alert('Please work this time!!!');
});
$('#SelectedFileName').change(function(){
alert('Please work this time!!!');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<select id="SelectedFileName">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
或者在你的问题上,你可以约束
onchange
直接在DropDownList中的事件。
@Html.DropDownListFor(x => x.SelectedFileName, Model.Files, new { Name = "map", @class = "form-control" , onchange = @"alert('Please work this time!!!')"})
编辑
这里是一个带有ASP.NET小示例的Ajax。
-
在中包含jquerylib
Razor
页面(HTML页面)
<script
src="https://code.jquery.com/jquery-2.2.4.js"
integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI="
crossorigin="anonymous"></script>
-
结合
Onchange
事件
id='selectedFileName'
下拉列表。
-
使用
post
方法执行Ajax调用,并使用第三个参数回调函数获取
MVC
结果。
像这样,你可以在
ShowAllMobileDetails
行动。
$('#SelectedFileName').change(function(){
//get id="SelectedFileName"
$.post('Home/ShowAllMobileDetails', $("form").serialize(),function(data){
alert(data);
});
});
[HttpPost]
public ActionResult ShowAllMobileDetails(HomeVM MV)
{
string SelectedValue = MV.Files.Count.ToString();
// your logic
string result = "Please work this time!!!";
return View(result);
}