我需要一些关于如何使用Razor引擎在MVC 5项目上安装Date Picker Bootstrap 3的指导方针.我在这里找到了这个链接但是无法在VS2013中使用它.
从上面后面的链接中的示例复制,我已经完成了以下操作:
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/bootstrap-datepicker.js", // ** NEW for Bootstrap Datepicker
"~/Scripts/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/bootstrap-datepicker.css", // ** NEW for Bootstrap Datepicker
"~/Content/site.css"));
Run Code Online (Sandbox Code Playgroud)
然后我将脚本添加到索引视图中,如下所示
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
$('.datepicker').datepicker(); //Initialise any date pickers
</script>
}
Run Code Online (Sandbox Code Playgroud)
现在,如何在这里调用日期选择器?
<div class="form-group input-group-sm">
@Html.LabelFor(model => model.DropOffDate)
@Html.TextBoxFor(model => model.DropOffDate, new { @class = "form-control", placeholder = "Enter Drop-off date here..." })
@Html.ValidationMessageFor(model => model.DropOffDate)
</div>
Run Code Online (Sandbox Code Playgroud) 有一个向用户显示信息的网页.如果用户决定打印它,我想要包含屏幕上不需要的其他信息,但在打印时会有所帮助.
为了实现这种行为,我试图div只为打印提供可见性.它没有工作:
<div class="visible-print hidden-lg hidden-md hidden-sm hidden-xs">
Run Code Online (Sandbox Code Playgroud)
我正在使用Bootstrap 3,并想知道是否有一种简单的方法来实现这一目标?
我创建了一个标准 Blazor 服务器应用程序。然后我添加了一个具有读/写操作的 API 控制器。
现在我想从索引页调用一个操作,但它不起作用。应用程序运行时没有错误,但没有返回预期的结果(状态=“等待激活”,方法=“null”和结果=“尚未计算”)。我在控制器操作中放置了一个断点,但程序从未命中它。
控制器:
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
// GET: api/<ValuesController>
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET: api/<ValuesController>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
}
Run Code Online (Sandbox Code Playgroud)
索引页:
<button class="btn btn-primary" @onclick="RetrieveGet">
GET
</button>
void RetrieveGet()
{
HttpClient Http = new HttpClient();
string baseUrl = "https://localhost:44382/";
var temp2 = Task.Run(async () => { await Http.GetStringAsync($"{baseUrl}api/values/5"); });
}
Run Code Online (Sandbox Code Playgroud)
Startup.cs(为简洁起见,删除了其他项目):
public void …Run Code Online (Sandbox Code Playgroud) 如何从引导按钮调用"注册"ActionLink(使用VS2013在标准MVC5项目上生成的那个)?
这是原始代码:
@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })
Run Code Online (Sandbox Code Playgroud)
我试过这个,但显然它不起作用:
<button type="button" class="btn btn-info" onclick="window.location.href('@Url.Action("Register", "Account")')">Add New User</button>
Run Code Online (Sandbox Code Playgroud) "索引"页面包含两个部分视图.一个是用户输入搜索条件,另一个是显示结果.如何仅更新"结果"视图中的数据?
我正在使用MVC 5和Razor.我已经看到了一些这方面的例子,主要是使用ajax和jquery.我问的是什么是最好的(更容易)解决方案
// INDEX VIEW:
<div id="div_Search">
@{Html.RenderPartial("~/Views/Shared/Search.cshtml", ViewBag.Model_Search );}
</div>
<div id="div_Results">
@{Html.RenderPartial("~/Views/Shared/Results.cshtml", ViewBag.Model_Results );}
</div>
// HOME CONTROLLER
Run Code Online (Sandbox Code Playgroud)
public class HomeController:Controller {MainContextDB db = new MainContextDB();
public ActionResult Index()
{
// Code to initialize ViewBag.Model_Search, etc...
....
// Code to initialize ViewBag.Model_Results, etc... (Values empty at startup)
....
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult GetResults([Bind(Include = "DropOffLoc,DropOffDate,PickUpDate")] Search search)
{
// Retrieve results using the search parameters, etc...
....
// THIS RETURNS THE VIEW WITH THE …Run Code Online (Sandbox Code Playgroud) 我有一个在我的开发服务器上的VS 2013上运行良好的Web应用程序,但是一旦我在IIS 7.5 2008 R2服务器上发布它,位于我的自定义脚本文件上的Ajax脚本就不再工作了,尽管其他JQuery脚本不调用Ajax的工作正常.为了让ajax在服务器上工作,还有什么需要做的吗?我已经阅读了一些帖子,但还没有找到答案.我在IIS和Ajax方面的经验有限.
//更新:
我已经发现Ajax脚本有效,问题最有可能发生在以下行:
"url:'/ Home/GetRates',//请求的网址"
使用debuger我发现远程服务器中没有调用GetRates()函数,尽管它位于本地(Under VS 2013)开发服务器中.我看到的唯一区别是路径,但不知道如何解决它.以下是Ajax脚本:
// Retrieve rates and update partial view
$(function () {
$('#reservSearch').submit(function () {
if ($(this).valid()) {
$("#theModal").modal("show"); // Display the in progress.....
$.ajax({
url: '/Home/GetRates', // URL for the request
data: $("#reservSearch").serialize(), // the data to send (will be converted to a query string)
type: "POST", // whether this is a POST or GET request
dataType: 'html', // the type of data we expect back
success: function (data) …Run Code Online (Sandbox Code Playgroud) 继其他人也已经做过的事情之后,在 Blazor 服务器应用程序 (Net Core 5.0 VS2019) 上,我实现了一个固定在顶部的 Bootstrap NavBarHorizontal,它工作正常,除了一个无法打开的下拉菜单。我只更改了两个页面中的代码,如下所示。其他一切都保持不变,包括 site.css。我也在下面的代码中包含了原始的 _Host.cshtml 。
// NavMenu
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-dark bg-primary fixed-top">
<div class="d-none d-sm-block" style="padding:0 20px 0 0;">
<img class="img-fluid" src="/Client/Images/CompanyLogo.png" alt="Company logo" style="width:auto; height:40px; padding:0 0 0 5px; margin:0" />
</div>
<button class="navbar-toggler" @onclick="ToggleNavMenu" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="@NavMenuCssClass navbar-collapse d-sm-inline-flex flex-sm-row-reverse" @onclick="CollapseNavMenu">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-light" href="" Match="NavLinkMatch.All">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-light" href="#">About</a>
</li> …Run Code Online (Sandbox Code Playgroud) 使用VS2019最新版本19.9.4并安装.NET SDK 6.0.100-preview.3现在我无法再编译该项目,因为它给出了下面描述的错误。如果我恢复到 NET 5.0,它工作正常。6.0 的原因是使用 Blazor 的热重载功能。我现在正处于设计几个 UI 的阶段,它应该可以节省我很多时间。
警告 CS8032 无法从 C:\Program Files\dotnet\sdk\6.0.100-preview.3.21202.5\Sdks\Microsoft.NET.Sdk.Razor 创建分析器 Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator 的实例\source-generators\Microsoft.NET.Sdk.Razor.SourceGenerators.dll:无法加载文件或程序集“Microsoft.CodeAnalysis,Version=3.10.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。系统找不到指定的文件。 RPManager C:\AppCenter\RPManager\CSC 1 Active
对于我到目前为止搜索的内容,我找不到一种方法来预设System.Windows.Controls.PrintDialog中的副本数量,这是WPF中使用的副本.我不能回退或使用另一个,因为我需要只有这个类提供的PrintVisual方法(afaik)除非有另一种方法,我正在考虑做一个for循环并调用dialog.PrintVisual()方法获取所需的数量copy.I还没有测试过,但我很确定它应该可行.我的问题:这是正确的做法吗?
我搜索网络寻找一种方法将"subItem1"和"subItem2"添加到"Home"项目菜单(在示例代码中),但我发现使用java或复杂的razor示例.是否有更简单的方法只使用剃须刀?
<nav>
<ul id="menu">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</nav>
Run Code Online (Sandbox Code Playgroud) 我需要回发用户在 DevExpress ListBox 中添加的项目,但是,根据公司的说法,这样做的方法是将项目存储在隐藏字段中,然后提交。我需要知道如何在视图中创建这个隐藏字段,我相信它需要是一个带有文本和值的列表(类似于传递的模型),然后如何在 jquery 中为其分配值。
注意: 1. 问题不是如何创建隐藏字段,而是特定类型。2.现在的方式,在控制器中,模型返回为空。
// This code is located in the Index.cshtml page
<div id="modalMain" class="modal fade hidden-print" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" style="padding-bottom:0;padding-top:0">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div id="modalMainData" class="modal-body" style=" padding: 0 10px 0 10px !important;">
</div>
</div>
</div>
</div>
// This code is located on ListBoxItemsModal.cshtml
@model List<ValueText>
@using (Html.BeginForm("", "", FormMethod.Post, new { @id = "formPostListBoxItems" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" …Run Code Online (Sandbox Code Playgroud) 注意:我已经在这个论坛上看到了一些解决方案,但它们不适用于我的具体情况。
在我的应用程序中,用户总是使用模态窗口编辑数据。当模态第一次打开时,只有一个“关闭”按钮可见。如果用户更改任何文本,此按钮将立即隐藏,“取消”和“保存”按钮变为可见。据我所知,实现这种方法的唯一方法是将事件连接到所有文本控件。表单中文本控件的数量不同,但不超过50个。我需要“id”并将“change”事件绑定到表单中的每个控件中。我的问题是,是否有更简单的方法?如果表单中的任何内容发生变化,就像一个事件?如果用户更改数据然后将其改回并且无论如何都会触发该事件,那是可以的。
@using (Html.BeginForm("", "", FormMethod.Post, new { @id = "formPostUnitDetails", @style = "padding-right:5px" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.IdNo)
@Html.LabelFor(m => m.UnitNo)
@Html.TextBoxFor(m => m.UnitNo, new { @id="txtUnitNo")
//..... 49 more text controls
<div class="panel-footer" style="margin-top:5px;">
<input id="btnCancel" type="button" class="btn btn-danger" data-dismiss="modal" value="CANCEL" style=" display: none;" />
<input id="btnSave" type="button" class="btn btn-success" value="SAVE CHANGES" style=" display: none;" />
<input id="btnClose" type="button" class="btn btn-info" data-dismiss="modal" value="CLOSE" />
</div>
Run Code Online (Sandbox Code Playgroud)
$(document).on("change", "#txtUnitNo", function () …Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×5
blazor ×3
c# ×3
jquery ×3
razor ×3
asp.net-core ×2
ajax ×1
asp.net ×1
bootstrap-4 ×1
html ×1
html5 ×1
iis ×1
javascript ×1
wpf ×1