以下htmla和javascript代码有什么问题
formToConvert.html
<html>
<head>
<title>ExampleToConvert</title>
<script type = "text/javascript" src = "con.js"></script>
</head>
<body>
<form id ="myform">
<input type = "text" id = "field1" value = "Enter text Here"/><br/>
<input type ="submit" value = "submit" onclick = "convert()"/>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
con.js
function convert()
{
var str ;
str = document.getElementById("field1");
document.writeln(str.toUpperCase());
}
Run Code Online (Sandbox Code Playgroud)
为什么上面的代码没有给我想要的结果呢?
我正在尝试从API控制器获取属性标记,以便我可以看到它在运行时允许的HTTP谓词.从下面的示例代码中,我希望能够获得[HttpGet]
标记.
[HttpGet]
public void MyResource()
{
// Controller logic
}
Run Code Online (Sandbox Code Playgroud)
我目前正在使用System.Reflection
它在运行时收集有关我的API的其他信息,但到目前为止,我无法检索[HttpGet
标记和其他Http
动词标记.我已经尝试了下面的每个解决方案而没有运气:
public void GetControllerMethodHttpAttribute()
{
MethodInfo controllerMethod = typeof(TestController).GetMethods().First();
// Solution 1
var attrs = controllerMethod.Attributes;
// Solution 2
var httpAttr = Attribute.GetCustomAttributes(typeof(HttpGetAttribute));
// Solution 3
var httpAttr2 = Attribute.GetCustomAttribute(controllerMethod, typeof(HttpGetAttribute));
// Solution 4
var httpAttr3 = Attribute.IsDefined(controllerMethod, typeof(HttpGetAttribute));
}
Run Code Online (Sandbox Code Playgroud)
我之前研究过的关于这个主题的所有问题只涉及Custom Attribute tags
并从中提取价值,但我找不到任何有关获得框架的信息Attribute tags
.
有谁知道如何获得[HttpGet]
属性标签?
谢谢!
我正在通过对 ASP.NET MVC 项目中的控制器的 AJAX 调用来获取 JSON 数据。我能够从 Web API 调用中获取 JSON 数据就好了。现在我想将这个 JSON 数据返回给success
我的 AJAX 调用中的函数,并将其传递给局部视图,而不是使用 jQuery 静态附加 JSON 数据。
C# 控制器:
[HttpGet]
[Route("company-info/companyinfogetapidata")]
[AllowAnonymous]
public ActionResult CompanyInfoGetApiData(string name, int CompanyCode, string city, string state, int zip)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("URL_BASE");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var request = client.GetAsync("URL_PATH");
var json = request.Result.Content.ReadAsStringAsync().Result;
JObject o = JObject.Parse(json);
JToken ApiData = o["results"];
// Here is where I want to insert pieces of the …
Run Code Online (Sandbox Code Playgroud)