当我尝试在LINQPad中使用Selfhosted WebAPI时,我只是得到了相同的错误,该类的控制器不存在.
我是否必须为WebAPI(控制器/类)创建单独的程序集,然后在我的查询中引用它们?
这是我正在使用的代码
#region namespaces
using AttributeRouting;
using AttributeRouting.Web.Http;
using AttributeRouting.Web.Http.SelfHost;
using System.Web.Http.SelfHost;
using System.Web.Http.Routing;
using System.Web.Http;
#endregion
public void Main()
{
var config = new HttpSelfHostConfiguration("http://192.168.0.196:8181/");
config.Routes.MapHttpAttributeRoutes(cfg =>
{
cfg.AddRoutesFromAssembly(Assembly.GetExecutingAssembly());
});
config.Routes.Cast<HttpRoute>().Dump();
AllObjects.Add(new UserQuery.PlayerObject { Type = 1, BaseAddress = "Hej" });
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
using(HttpSelfHostServer server = new HttpSelfHostServer(config))
{
server.OpenAsync().Wait();
Console.WriteLine("Server open, press enter to quit");
Console.ReadLine();
server.CloseAsync();
}
}
public static List<PlayerObject> AllObjects = new List<PlayerObject>();
public class PlayerObject
{
public uint Type { get; …
Run Code Online (Sandbox Code Playgroud) 我正在写一个扩展来用my -function 替换普通函数.string.Format
FormatNamed
到目前为止,我已经有了这段代码,但我想改变输入参数的方式
void Main()
{
string sql = "SELECT {fields} FROM {table} WHERE {query}"
.FormatNamed(new { fields = "test", table = "testTable", query = "1 = 1" });
Console.WriteLine(sql);
}
public static class StringExtensions
{
public static string FormatNamed(this string formatString, dynamic parameters)
{
var t = parameters.GetType();
var tmpVal = formatString;
foreach(var p in t.GetProperties())
{
tmpVal = tmpVal.Replace("{" + p.Name + "}", p.GetValue(parameters));
}
return tmpVal;
}
}
Run Code Online (Sandbox Code Playgroud)
不是最漂亮的替换,但它完成了这项工作.
无论如何.我想改变所以我可以执行它
.FormatName(field: "test", table: …
Run Code Online (Sandbox Code Playgroud) 我在OnClientClick上遇到了一些问题.
我在这个webform中添加了一个按钮.
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
style="top: 307px; left: 187px; position: absolute; height: 26px; width: 90px"
Text="Submit" OnClientClick="return validate()" />
Run Code Online (Sandbox Code Playgroud)
我正在写一个javascript里面<head>
的内容<title>
.
<script language="javascript" type="text/javascript">
function validate() {
if (document.getElementById("<%=TextBox1%>").value == "") {
alert("textbox1 should not be empty");
}
else if(document.getElementById("<%=TextBox2 %>").value==""){
alert("textbox2 should not be empty");
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
TextBox1
并且TextBox2
是两个文本框的Id.
但是,当我单击"提交"按钮时,OnClick正在触发,但OnClientClick未触发.
有什么问题 ?
请帮忙.