如何在MVC4中显示弹出窗口 [英] How to Show Popup in MVC4
问题描述
我的视图中有如下网格视图
Hi,
I have a gridview like below in my view
<table id="list" cellspacing="0" cellpadding="0">
<tr>
<th>
@Html.DisplayNameFor(model => model.UserName)
</th>
@*<th>
@Html.DisplayNameFor(model => model.Password)
</th>*@
<th>
@Html.DisplayNameFor(model => model.Address)
</th>
<th>
@Html.DisplayNameFor(model => model.MobileNumber)
</th>
<th>
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.UserName)
</td>
@* <td>
@Html.DisplayFor(modelItem => item.Password)
</td>*@
<td>
@Html.DisplayFor(modelItem => item.Address)
</td>
<td>
@Html.DisplayFor(modelItem => item.MobileNumber)
</td>
<td>
@*@Html.ActionLink("Edit", "../SaveData/SaveData", new { id = item.UserID }) |*@
@Html.ActionLink("Edit", "Details", new { id = item.UserID }, new { @class = "details-modal", @onclick = "javascript:foo();" })
@Html.ActionLink("Delete", "Delete", new { id = item.UserID })
</td>
</tr>
}
点击弹出窗口显示的操作链接。在下面的linke中使用的代码
when click on the action link a popup is showing. the code used in linke below
@ {
var user =(User)ViewData [userdetails];
// if(ViewData [userdetails]!= null)
// {
// ViewBag.username = @ user.UserName;
//}
//ViewBag.userdata=\"fdfdsfsdfsdfsd;
//ViewBag.userdata=@user.UserName;
@ Html.ValidationSummary(true);
< input type =textid =user/>
@{
var user = (User)ViewData["userdetails"];
//if (ViewData["userdetails"] != null)
//{
// ViewBag.username = @user.UserName;
//}
//ViewBag.userdata="fdfdsfsdfsdfsd";
//ViewBag.userdata=@user.UserName;
@Html.ValidationSummary(true);
<input type="text" id="user" />
@ Html.LabelFor(model => @user .UserName)
@Html.LabelFor(model => @user.UserName)
@ Html.EditorFor(model => @ user.UserName)
@ Html.ValidationMessageFor(model => @ user.UserName)
@Html.EditorFor(model => @user.UserName)
@Html.ValidationMessageFor(model => @user.UserName)
@ Html.LabelFor(model => @ user.Password)
@Html.LabelFor(model => @user.Password)
@ Html.Password(密码)
@ Html.ValidationMessageFor(model => @ user.Password)
@Html.Password("Password")
@Html.ValidationMessageFor(model => @user.Password)
@ Html.LabelFor(model => @ user.Address)
@Html.LabelFor(model => @user.Address)
@ Html.EditorFor(model => @ user.Address)
@ Html.ValidationMessageFor(model => @ user.Address)
@Html.EditorFor(model => @user.Address)
@Html.ValidationMessageFor(model => @user.Address)
@ Html.LabelFor(model => @user。 MobileNumber)
@Html.LabelFor(model => @user.MobileNumber)
@ Html.EditorFor(model => @ user.MobileNumber)
@ Html.ValidationMessageFor(model => @ user.MobileN umber)
@Html.EditorFor(model => @user.MobileNumber)
@Html.ValidationMessageFor(model => @user.MobileNumber)
< input type =submitvalue =Create/> < br $> b $ b
<input type="submit" value="Create" />
< script type =text / jscript>
$('#my-dialog')。dialog({
autoOpen:false,
宽度:400,
可调整大小:false,
modal:true
});
$('。details-modal')。click(function(){
// var username ='@ ViewBag.username';
/ /document.getElementById('user').value = username;
var theURL = $(this).attr('href');
$('#my-dialog')。load(theURL,function(){
$(this).dialog('open');
});
返回false; //确保浏览器不会重定向到链接的URL
});
i希望用每个文本框中的相应数据填充点击了一行。我怎么可能?
<script type="text/jscript">
$('#my-dialog').dialog({
autoOpen: false,
width: 400,
resizable: false,
modal: true
});
$('.details-modal').click(function () {
//var username = '@ViewBag.username';
//document.getElementById('user').value = username;
var theURL = $(this).attr('href');
$('#my-dialog').load(theURL, function () {
$(this).dialog('open');
});
return false; // ensures the browser is not redirected to the link's URL
});
i want to populate each textbox with the corresponding data in the clicked row. how can i possible?
推荐答案
('#my-dialog')。对话框({
autoOpen:false,
宽度:400,
可调整大小:false,
modal:true
});
('#my-dialog').dialog({
autoOpen: false,
width: 400,
resizable: false,
modal: true
});
('。details-modal')。click(function(){
// var username ='@ ViewBag.username';
//document.getElementById('user').value = username;
var theURL =
('.details-modal').click(function () {
//var username = '@ViewBag.username';
//document.getElementById('user').value = username;
var theURL =
(this).attr('href');
(this).attr('href');
这篇关于如何在MVC4中显示弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!