我正在调用ASP.NET MVC操作
public JsonResult GetPatient(string patientID)
{
...
Run Code Online (Sandbox Code Playgroud)
来自JavaScript使用jQuery.以下呼叫有效
$.getJSON(
'/Services/GetPatient',
{ patientID: "1" },
function(jsonData) {
alert(jsonData);
});
Run Code Online (Sandbox Code Playgroud)
而这一个则没有.
$.ajax({
type: 'POST',
url: '/Services/GetPatient',
data: { patientID: "1" },
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(jsonData) {
alert(jsonData);
},
error: function() {
alert('Error loading PatientID=' + id);
}
});
Run Code Online (Sandbox Code Playgroud)
两者都达到了action方法,但是对于$ .ajax调用,patientID值为null.我想使用$ .ajax调用来进行一些高级回调.
任何想法都赞赏.
以下MVC4 Razor布局文件加载在Bundle.config中创建的多个脚本和css包.
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<title>XXX Beta</title>
@Scripts.Render(
"~/bundles/bundle_jquery",
"~/bundles/bundle_modernizr",
"~/bundles/bundle_foundation",
"~/bundles/bundle_jhs")
@Styles.Render(
"~/Content/bundle_foundation",
"~/Content/bundle_jhs")
@RenderSection("pageHeadContent", false)
</head>
<body>
<div id="bodyContainer">
@Html.Partial("Partial/_header")
<div id="contentContainer">
<div id="mainContentContainer">
<div id="sidebarContainer">
@RenderSection("sidebarContent", required: true)
</div>
@RenderBody()
</div>
<div class="clearBoth">
</div>
</div>
@Html.Partial("Partial/_footer")
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
呈现页面时,会发生以下错误.由于某种原因,无法识别@Scripts和@Styles命令.如果我在文件中键入"@Scripts",则Intellisense不会显示/显示命令.该项目确实引用了Bundle.config中使用的System.Web.Optimization.
什么可能导致@Scripts和@Styles命令无法被识别?
'/'应用程序中的服务器错误.
编译错误
描述:编译服务此请求所需的资源时发生错误.请查看以下特定错误详细信息并相应地修改源代码.
编译器错误消息:CS0103:当前上下文中不存在名称"脚本"
来源错误:
第4行:第5行:XXX Beta第6行:@ Scripts.Render(第7行:"〜/ bundles/bundle_jquery",第8行:"〜/ bundles/bundle_modernizr",
源文件:c:\ Users\username\Documents\Visual Studio 2010\Projects\XXX\Solution\xxx.website\Views\Shared_sidebarLayout.cshtml行:6
显示详细的编译器输出:
显示完整编译源:
可能重复:
格式化Microsoft JSON日期?
ASP.NET函数Json()
格式化并返回日期为
{"d":"\/Date(1240718400000)\/"}
Run Code Online (Sandbox Code Playgroud)
必须在客户端处理这是有问题的.您对来回发送日期值的方法有何建议?
我在JavaScript中有以下复杂对象,其中包含过滤器选项
var filter={caseIdentifiter:'GFT1',userID:'2'};
Run Code Online (Sandbox Code Playgroud)
我想传递给ASP.NET MVC4 WebApi控制器GET
[HttpGet]
public IEnumerable<JHS.Repository.ViewModels.CaseList> Get([FromBody]Repository.InputModels.CaseListFilter filter)
{
try
{
return Case.List(filter);
}
catch (Exception exc)
{
//Handle exception here...
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
使用jQuery ajax调用
var request = $.ajax({
url: http://mydomain.com/case,
type: 'GET',
data: JSON.stringify(filter),
contentType: 'application/json; charset=utf-8',
cache: false,
dataType: 'json'
});
Run Code Online (Sandbox Code Playgroud)
ASP.NET控制器方法中的"filter"对象为"null".如果我将其更改为POST,则正确传递过滤器对象.有没有办法将复杂的对象传递给GET?
我不想将参数分离到URL,因为会有一些参数会使它效率低下,很难有可选参数,这样即使添加了新参数,方法签名也保持不变.
我很熟悉将appsettings.json部分加载到.NET Core startup.cs中的强类型对象中.例如:
public class CustomSection
{
public int A {get;set;}
public int B {get;set;}
}
//In Startup.cs
services.Configure<CustomSection>(Configuration.GetSection("CustomSection"));
//Inject an IOptions instance
public HomeController(IOptions<CustomSection> options)
{
var settings = options.Value;
}
Run Code Online (Sandbox Code Playgroud)
我有一个appsettings.json部分,其键/值对随着时间的推移会在数量和名称上有所不同.因此,对类中的属性名称进行硬编码是不切实际的,因为新的键/值对需要在类中进行代码更改.一些键/值对的小样本:
"MobileConfigInfo": {
"appointment-confirmed": "We've booked your appointment. See you soon!",
"appointments-book": "New Appointment",
"appointments-null": "We could not locate any upcoming appointments for you.",
"availability-null": "Sorry, there are no available times on this date. Please try another."
}
Run Code Online (Sandbox Code Playgroud)
有没有办法将此数据加载到MobileConfigInfo Dictionary对象中,然后使用IOptions模式将MobileConfigInfo注入控制器?
作为一个新的iOS开发人员,我正在尝试确定在iOS4 +中创建可重用控件的最佳方法.例如,如果我想创建一个可以在多个其他视图中使用的自定义UIImageView,那么最佳方法是什么.
我创建了包含以下文件的控件:
假设我想要一个使用.nib文件的控件.
我该怎么做:
任何见解或参考赞赏.谢谢
我创建一个自定义UIToolbar
为使用UIView
的UINavigationBar.navigationitem.titleView
属性.我想通过获取.navigationitem的当前高度而不是硬编码来将工具栏高度调整为.navigationitem的高度.有没有办法获得身高值?
给出以下字符串扩展方法
namespace JHS.ExtensionMethods
{
public static class StringExtensions
{
public static string ToUSAPhone(this String str)
{
return String.Format("{0:(###) ###-####}", Double.Parse(str));
}
}
}
Run Code Online (Sandbox Code Playgroud)
@using语句被添加到MVC4 Razor视图中
@using JHS.ExtensionMethods;
Run Code Online (Sandbox Code Playgroud)
以下字符串值调用扩展方法
@Model.producer.phone.ToUSAPhone()
Run Code Online (Sandbox Code Playgroud)
这会导致以下错误
'string' does not contain a definition for 'ToUSAPhone'
Run Code Online (Sandbox Code Playgroud)
我还尝试将命名空间放在/ Views文件夹的web.config中并收到相同的错误.
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="JHS.ExtensionMethods"/>
</namespaces>
</pages>
Run Code Online (Sandbox Code Playgroud)
我通过在C#类中调用相同的调用来验证扩展方法的工作原理
string test=producer.phone.ToUSAPhone();
Run Code Online (Sandbox Code Playgroud)
看来扩展方法的引用在MVC4 Razor视图中不可用,但我无法弄清楚为什么?
我需要在类库程序集中编码URL,我不想引用System.Web.URL包含多个空格
https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.quote where symbol in ("YHOO","AAPL")&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=
Run Code Online (Sandbox Code Playgroud)
当我使用System.Net.WebUtility.UrlEncode()时,空格将替换为"+",这不起作用.我需要用%20替换它们
如何在不引用System.Web的情况下实现此目的?
asp.net-mvc ×4
c# ×4
asp.net ×2
ios ×2
jquery ×2
json ×2
razor ×2
.net ×1
.net-core ×1
ajax ×1
asp.net-core ×1
datetime ×1
http-get ×1
javascript ×1
json.net ×1
objective-c ×1
xcode ×1