- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 Index.cshtml 文件中有一个按钮定义如下:
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal">
Add Value
</button>
点击按钮打开一个模态窗口。我的模式在 Index.cshtml 文件中定义如下:
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Add a Value</h4>
</div>
<div class="modal-body">
@(Html.Kendo().TabStrip()
.Name("tabstrip")
.Items(ts =>
{
ts.Add().Text("Pick a school").Selected(true).LoadContentFrom(Url.Action("SchoolPartial", "Institution"));
})
)
</div>
</div>
</div>
下面是我的局部图(SchoolPartial.cshtml):
<div class="col-md-12">
@(Html.Kendo().Editor()
.Name("schoolEditor")
.Tag("div")
.Tools(tools => tools
.Clear()
.Bold().Italic().Underline().Strikethrough()
.JustifyLeft().JustifyCenter().JustifyRight().JustifyFull()
.CreateLink().Unlink()
.InsertImage()
.TableEditing()
.FontColor().BackColor()
)
.Value(@<text><p>
<div class="container-fluid">
<div class="row">
<div class="col-md-4">Senior School</div>
</div>
</div>
</p></text>))
</div>
现在,用户点击 Index.cshtml 文件中的'Add Value' 按钮,'myModal' 窗口打开,并在 'myModal' 窗口中的“选择学校”选项卡,它加载了 “SchoolPartial” 选项卡,我希望用户能够单击“高中”div。当用户点击 SchoolPartial.cshtml 中的高中 div 时,我希望将 id = 2 传递到我的 Index.cshtml,然后它将从数据库中加载学校名称和地址详细信息并将其显示在 Index.cshtml 中。
我怎样才能实现这种行为。
谢谢!
编辑:
在我的 SchoolPartial.cshtml 中,为了让我的 div 可以点击,我用 anchor 标记包围了我的 div,如下所示:
<a href="@Url.Action("RetrieveSchoolDetails", "School", new {schoolId= "2" })">
<div class="col-md-4">senior school</div>
</a>
这里的 School 是我的 Controller (SchoolController.cs),RetrieveSchoolDetails 是操作方法。
这就是我定义 RetrieveSchoolDetails 方法的方式:
public void RetrieveSchoolDetails (string schoolId= null)
{
var schoolDetail = db.School.Where(e => e.SchoolId== schoolId).ToList();
string Address = Convert.ToString(schoolDetail .Select(e => e.Address));
string Name = Convert.ToString(schoolDetail .Select(e => e.Name));
string School= Name + Address;
ViewBag.SchoolSelection = School;
}
现在我想,一旦信息进入 ViewBag,我想关闭模态窗口,以便选择和 ViewBag 信息显示在 Index.cshtml 中。
我不确定如何从 Controller 关闭我的引导模式,以便它向我显示 Index.cshtml 中的数据。
或者可能只是向我显示模态,用户可以手动关闭模态,以便 ViewBag 信息仍然存在。当我运行我的项目时,在为 ViewBag 赋值后,浏览器继续处理,我无法单击我的模式来关闭它。
求推荐!
谢谢
编辑 2:
我编辑了我的代码并使用 div 单击调用 javascript 函数,然后使用 ajax 调用 Controller 的方法 - RetrieveSchoolDetails 并从该 Controller 方法返回部分 View 。
它现在所做的是,返回全屏显示学校地址的部分 View 。也就是说,它使用生成的学校地址将我重定向到我的局部 View 。
但是我想关闭模式,然后在我的父页面 (Index.cshtml) 中显示该部分 View 。
下面是我的代码添加-
下面的div在SchoolPartial.cshtml中
<div onclick="GetAddress('2')" class="col-md-4">senior school</div>
JavaScript 函数
<script>
function GetAddress(code)
{
$.ajax({
url: '/School/RetrieveSchoolDetails?schoolID=2',
contentType: 'application/html; charset=utf-8',
type: 'GET',
dataType: 'html'
})
.success(function (result) {
$('#npAddress').html(result); //npAddress is id of my div inside
//Index.cshtml where I want to display the partial.
//Here I want to close the modal window
//and show Index.cshtml in it's filled state.
})
.error(function (xhr, status) {
alert(status);
})
};
</script>
下面是我的 Controller 方法:
public void RetrieveSchoolDetails (string schoolId= null)
{
var schoolDetail = db.School.Where(e => e.SchoolId== schoolId).ToList();
string Address = Convert.ToString(schoolDetail .Select(e => e.Address));
string Name = Convert.ToString(schoolDetail .Select(e => e.Name));
string School= Name + Address;
ViewBag.SchoolSelection = School;
return PartialView("_schoolAddress");
}
下面是我的_schoolAddress.chtml部分
@ViewBag.SchoolSelection
最佳答案
首先,你真的不需要在这里使用部分。使用 partials 的目的是在其中放置一些需要在多个地方(不同页面)重复使用的 html 代码。通过将它放在一个部分中,然后从多个页面调用该部分,您可以使您的项目更易于维护(任何更改只需要进行一次)。但是,partials 增加了一定程度的复杂性,不建议初学者使用。它们可以是强大的工具,但让我们从基础开始,然后逐步完善。
其次,我不会在 Razor 上使用任何其他插件(例如剑道)。使用它没有任何问题,但让我们暂时保持简单。另外, Razor 本身就非常强大。
我为您编写了一些内容,但您必须填补空白。
@model MyProject.Models.MyModel
<div class="">
<button type="button" class="btn btn-default" data-toggle="modal" onclick="AddValue()">
Add Value
</button>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Add a Value</h4>
</div>
<div class="modal-body">
<!-- some tabs here? -->
<!-- put code for tabs here, don't use a partial -->
<div onclick="GetAddress(2)" class="col-md-4">senior school</div>
</div>
</div>
</div>
</div>
<script>
function AddValue()
{
$('myModal').modal();
}
function GetAddress(id)
{
$.ajax(
{
url: '/School/RetrieveSchoolDetails?schoolID' + id,
contentType: 'application/html; charset=utf-8',
type: 'GET',
contentType: 'application/json',
success: function (result) {
$('#npAddress').text(result);
},
error: function (xhr, status) {
alert(status);
}
});
}
</script>
在你的 Controller 中:
public JsonResult RetrieveSchoolDetails (string schoolId)
{
// don't use a default null here unless you plan on handling it somehow
// otherwise the next line would throw an error
var schoolDetail = db.School.Where(e => e.SchoolId== schoolId).ToList();
string Address = Convert.ToString(schoolDetail .Select(e => e.Address));
string Name = Convert.ToString(schoolDetail .Select(e => e.Name));
string School= Name + Address;
// may need to format this depending on exactly what you want to return
return Json(school);
}
请记住,整个学习过程意味着从简单开始,然后逐渐变得更复杂。
关于asp.net-mvc - 将数据从模态内的局部 View 传递到主视图,然后关闭模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36802114/
是否有更快的算法来计算 (n! modulo m)。在每个乘法步骤都比减少更快。并且有没有比左右二元法更快的算法来计算 (a^p modulo m)。 这是我的代码:n!模数m ans=1 for(i
我有非常简单的代码循环遍历数组中的元素并检查是否index % 2 == 0。如果是这样,它应该改变颜色。 var e = document.getElementById("list").childN
让我简短一点。我正在计算 alert((Math.pow(7,35))%71) 但它给了我 61,而结果必须是 70。怎么了? 最佳答案 正如其他人之前提到的关于使用 Math.pow(7,35) 的
我试图弄清楚如何在汇编中计算模 10,所以我在 gcc 中编译了以下 c 代码,看看它想出了什么。 unsigned int i=999; unsigned int j=i%10; 令我惊讶的是我得到
例如使用以下输入: int num = -100 int divisor = 10 => -100 mod 10 = 0 (Edge-case: negative numbers as inpu
这个问题在这里已经有了答案: Random float number generation (14 个答案) 关闭 9 年前。 在 C++ 中,我希望得到一个随机 float 。据我所知,典型的随机
我试图找到潜在阶乘素数的除数(n!+-1 形式的数),因为我最近购买了 Skylake-X 工作站,我认为我可以使用 AVX512 指令提高一些速度。 算法简单,主要步骤是对同一个除数重复取模。主要是
我有一个保存角度(以度为单位)的变量,该角度可以是正值也可以是负值。我现在需要确保该数字仅在 0 到 360 之间。该数字是 double 。 执行此操作的好算法是什么?简单地执行角度 % 360 是
我有一个 UInt8 数组,我想计算 CheckSum8 模 256。如果字节总和小于 255,checkSum 函数返回正确的值。 例如 let bytes1 : [UInt8] = [1, 0xa
使用海湾合作委员会: printf("%i \n", -1 % (int)4); printf("%u \n", -1 % (unsigned int)4); 输出: -1 3 我可以跨平台依赖这种行
我无法理解代码中几行的含义。我最近开始学习 C++,并阅读了 Bjarne Stroustrup 的“编程:使用 C++ 的原理和实践”。第四章有个问题让我很困惑,所以我在网上搜索了一个解决方案以供引
我试图解决一个涉及大阶乘模质数的问题,并在另一个人的解决方案中发现了以下算法: long long factMod (long long n, long long p) { long long
我正在尝试计算 𝐹𝑛 模 𝑚,其中 𝑛 可能非常大:高达 10^18,𝐹𝑛 是第 n 个斐波那契数这是我的代码,它适用于小数字,但对于大数字,它会抛出 OutOfMemoryError 或
我有两个以 16 为模的循环整数,因此它们的值介于 0 和 15 之间。 我需要比较两个数字以确定 n_1 是否大于 n_0 n_1 > n_0 很明显,这个没有准确定义,所以我定义n_1如果小于前面
我一直在尝试使用 Java 处理一些更大的值,但遇到了一些我不理解的问题。出于某种原因,Java 似乎喜欢给我垃圾数据(尽管,我更可能告诉它给我垃圾数据) 这是一个片段,为清楚起见进行了编辑:
好吧,我今天做了一个小函数,它应该会生成一个随机字符串。 std::string randString(size_t length) { std::string randStr; fo
Ruby 的负数取模规则不明确。在 IRB 中: -7 % 3 == 2 应该是1!为什么? 最佳答案 因为 -7/3 在 Ruby 的整数除法语义下是 -3。 3*-3 是 -9,所以会留下 2
这个问题在这里已经有了答案: Calculating pow(a,b) mod n (14 个答案) 关闭 6 年前。 在 Javascript 中是否有获取大数模数的技巧。我用 modulo(7,
此代码使用公式 (a^x) % 101 检查值 a 是否唯一映射到值 1 到 100 local function f(a) found = {} bijective = true
在《Core Java Volume1》一书中有一条警告: CAUTION: The right-hand side argument of the shift operators is reduce
我是一名优秀的程序员,十分优秀!