我已经看到了很多关于这方面的问题,但是对于如何在使用DefaultDisplayMode类确定移动网站的Razor/MVC网站中如何做到这一点没有明确的答案.此外,很多答案只是代码片段,没有代码所在的详细信息(在控制器,视图,CSS等?)
所以首先,有一个调用EvaluateDisplayMode()的Global文件:
的Global.asax.cs
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
BundleConfig.RegisterBundles(BundleTable.Bundles);
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
DeviceConfig.EvaluateDisplayMode();
}
}
Run Code Online (Sandbox Code Playgroud)
App_Start文件夹中的EvaluateDisplayMode基于GetOverriddenUserAgent()类型设置移动和桌面类:
DeviceConfig.cs
public static class DeviceConfig
{
const string DeviceTypePhone = "Mobile";
public static void EvaluateDisplayMode()
{
DisplayModeProvider.Instance.Modes.Insert(0,
new DefaultDisplayMode(DeviceTypePhone)
{
ContextCondition = (ctx => (
(ctx.GetOverriddenUserAgent() != null) &&
(
(ctx.GetOverriddenUserAgent().IndexOf("android", StringComparison.OrdinalIgnoreCase) >= 0) ||
(ctx.GetOverriddenUserAgent().IndexOf("iPhone", StringComparison.OrdinalIgnoreCase) >= 0) ||
(ctx.GetOverriddenUserAgent().IndexOf("Window Phone", StringComparison.OrdinalIgnoreCase) >= 0) ||
(ctx.GetOverriddenUserAgent().IndexOf("Blackberry", StringComparison.OrdinalIgnoreCase) >= 0)
)
))
});
}
}
Run Code Online (Sandbox Code Playgroud)
每个页面都有一个名为_AdminMaster.Mobile.cshtml的Layout/Master页面,它使用一个名为PhoneCommon.css的CSS文件.CSS没有什么特别之处(移动与桌面;没有媒体查询;我没有正确的CSS,我从客户端使用的另一个开发人员那里继承了它),除了高度没有一直延伸到底部页.这是CSS的一部分(相当冗长):
#main #content …Run Code Online (Sandbox Code Playgroud) 我在Windows 10环境中使用Visual Studio 2015.Visual Studio经常崩溃.解决方案打开很好,但在输入几个字母后,我收到一条消息,说明发生了错误,必须关闭Visual Studio.我在网上搜索并发现如何在诊断模式下运行VS(devenv/log).我试过这个,看看ActivityLog.xml中的几个错误.我不知道这些是什么意思,我在网上找不到任何关于它们的信息.我已经更新了所有Visual Studio扩展,但这没有帮助.我试过修复VS,但这也无济于事.有人可以解释我如何诊断和解决问题吗?
以下是日志中的错误消息:
<entry>
<record>161</record>
<time>2017/05/08 14:53:38.815</time>
<type>Error</type>
<source>Microsoft.VisualStudio.CommonIDE.ExtensibilityHosting.VsShellComponentModelHost</source>
<description>Still unable to load MEF component DLL: Could not load file or assembly 'Microsoft.VisualStudio.Workspaces.Contracts, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.</description>
<path>C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\COMMON7\IDE\EXTENSIONS\RV0KRPV2.PBV\TMLanguage.dll</path>
</entry>
<entry>
<record>162</record>
<time>2017/05/08 14:53:38.822</time>
<type>Error</type>
<source>Microsoft.VisualStudio.CommonIDE.ExtensibilityHosting.VsShellComponentModelHost</source>
<description>Still unable to load MEF component DLL: Could not load file or assembly 'Microsoft.VisualStudio.WindowsAzure.CommonAzureTools.Contracts.1.7, Version=1.7.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system …Run Code Online (Sandbox Code Playgroud) 我正在用Javascript设置Kendo文本框For的值,在屏幕上显示该值,但是在到达控制器时出现字段为null且模型状态无效的错误。如何设置文本框的值并保留该值,以便模型状态有效?
这是我所拥有的:
当用户从下拉列表中选择一个值时,Javascript会按以下方式设置Title的值:
$("#Title").val("WO# " + workOrderID);
Run Code Online (Sandbox Code Playgroud)
文本显示在屏幕上(请参见下面的屏幕截图)。但是,当用户单击“保存”按钮时,他们会收到错误消息,“标题”不能为空。如果我在控制器中查找当用户单击“保存”时命中的方法,则可以在模型中看到Title确实为空,这导致模型状态无效。我添加了Javascript,以便在使用上面的代码进行设置后立即获得Title的值,并且它为null。
我尝试了几种在javascript中设置Title的方法;基本上是这样的:
alert($("#Title").data("kendoTextBox").value());
Run Code Online (Sandbox Code Playgroud)
并返回“找不到”错误。
那么,如何设置标题不仅显示在屏幕上,还可以被控制器识别并且模型状态无效?
从下拉列表中选择工作订单后,标题将设置为包括此值,并且标题现在在屏幕上具有一个值:
$(“#Title”)。val(“ WO#” + workOrderID);

但是,当用户单击“保存”并将代码转到控制器时,“模型状态”无效,并且“标题”的值为null:
这是调度程序的代码:
@(Html.Kendo().Scheduler<SchedTasksModel>()
.Name("scheduler")
.Date(DateTime.Today)
.StartTime(DateTime.Parse(string.Format("{0} {1}", DateTime.Today.ToShortDateString(), "07:00")))
.Height(600)
.Views(views =>
{
views.DayView();
views.WeekView(weekView => weekView.Selected(true));
views.MonthView();
views.AgendaView();
})
.Editable(editable => editable.TemplateName("KoorsenEditor"))
.Timezone("Etc/UTC")
.Events(e => { e.Edit("sched_edit"); })
.Resources(resource =>
{
resource.Add(m => m.TaskType)
.Title("Type")
.DataTextField("Text")
.DataValueField("Value")
.DataColorField("Color")
.BindTo(new[]
{
new {Text = "Work Order", Value = 1, Color = …Run Code Online (Sandbox Code Playgroud) 我继承了一个我知之甚少的网站。我曾经使用过 asp.net/C# 网站,但这似乎有所不同。后面没有代码可供我设置断点并单步执行。程序中的一些参考资料也找不到。我的一般问题是:如何在 Visual Studio 中调试该程序?
与此示例代码相关的具体问题:
该程序继承“Company.Program.SystemLogin”。我在任何代码中都找不到该类。为什么不可以以及如何找到它?
<%@ Page Language="vb" AutoEventWireup="false" Inherits="Company.Program.SystemLogin" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Company CMS</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<style>
BODY { FONT-SIZE: 11px; FONT-FAMILY: Verdana, Helvetica, sans-serif; BACKGROUND-COLOR: #ffffff }
INPUT { FONT-SIZE: 11px; COLOR: #000000; FONT-FAMILY: Verdana, Helvetica, sans-serif }
TEXTAREA { FONT-SIZE: 11px; COLOR: #000000; FONT-FAMILY: Verdana, Helvetica, sans-serif } …Run Code Online (Sandbox Code Playgroud)我在C#中创建了一个带有4个参数的API.这工作正常.要让它接受XML文件而不是参数,我需要做些什么?
这是代码:
public string Post(int orderID, bool internalUse, string subject, string message)
{
return "orderID: " + orderID + "; internalUse: " + internalUse + "; subject: " + subject + "; message: " + message;
}
Run Code Online (Sandbox Code Playgroud)
我可以使用像这样的Post请求从Postman调用它:
http://localhost:58069/api/values/SendEmail?orderID=1234&internalUse=true&subject=Hello&message=Hello World
Run Code Online (Sandbox Code Playgroud)
我宁愿使用XML文档,其中URL如下所示:
http://localhost:58069/api/values/SendEmail
Run Code Online (Sandbox Code Playgroud)
并且参数将在XML文件中指定.
我尝试使用这个XML文件(也尝试使用和不使用嵌套在响应标记中的参数以及使用和不使用XML版本标记):
<?xml version="1.0" encoding="utf-8" ?>
<response>
<orderID>1234</orderID>
<internalUse>true</internalUse>
<subject>Hello</subject>
<message>Hello World</message>
</response>
Run Code Online (Sandbox Code Playgroud)
以下是Postman中请求的外观:
这会触及我的SendEmail方法,但所有变量都是空白的.我需要在代码方面做些什么,还是我没有正确创建Postman请求?
asp.net ×2
asp.net-mvc ×1
c# ×1
code-behind ×1
css ×1
debugging ×1
javascript ×1
jquery ×1
kendo-ui ×1
mobile ×1
post ×1
rest ×1
telerik ×1
vb.net ×1
xml ×1