有没有我可以看到当前Ajax.ActionLink方法的方法定义,因为我希望能够使用自定义方法扩展它,但不确定其当前的方法定义
编辑:这是我到目前为止:
public static class AjaxExtensions
{
public static IHtmlString MyActionLink(
this AjaxHelper htmlHelper,
string linkText,
string action,
string controller,
object routeValues,
AjaxOptions ajaxoptions,
object htmlAttributes
)
{
var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
var anchor = new TagBuilder("a");
anchor.InnerHtml = linkText;
anchor.Attributes["href"] = urlHelper.Action(action, controller, routeValues);
anchor.MergeAttributes(new RouteValueDictionary(htmlAttributes));
return MvcHtmlString.Create(anchor.ToString());
}
}
Run Code Online (Sandbox Code Playgroud)
但显然我需要添加默认Ajax.ActionLink包含的AjaxOptions内容,但我不确定它的定义是什么样的.
这样做的原因是我希望linkText是一个HtmlString,因为我想这样做: @Ajax.MyActionLink("<span class="highlight">Hello</span> World",...)
第二编辑:
我现在收到编译错误:
...does not contain a definition for 'MyActionLink' and the best extension method overload 'MyProject.Helpers.AjaxExtensions.MyActionLink(System.Web.Mvc.AjaxHelper, System.Web.HtmlString, string, object, System.Web.Mvc.Ajax.AjaxOptions)' has some invalid …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
function JobTask() {
var self = this;
self.description = ko.observable('').extend({
required: true
});
self.priority = ko.observable('').extend({
number: true,
required: true
});
self.complete = ko.observable(false);
}
function CreateJobViewModel() {
var self = this;
self.task = ko.observable(new JobTask());
self.taskErrors = ko.validation.group(self.task);
self.addTask = function () {
if (self.taskErrors().length) {
console.log(self.taskErrors());
self.taskErrors.showAllMessages();
}
else {
...
}
};
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我添加任务时,即使我正确输入了字段,它也会因某些原因无效.控制台输出[null].经过进一步调查,似乎即使我没有正确输入我的字段,我的taskErrors数组中的第一项始终是[null].所以看起来像:[null], "This field is required.".不知道我做错了什么?
这是我创建的问题的小提琴:http://jsfiddle.net/5kh6h/1/
我有以下存储库类:
public class Repository<T> : IDisposable where T : new()
{
public IDbConnectionFactory DbFactory { get; set; } //Injected by IOC
IDbConnection db;
IDbConnection Db
{
get
{
return db ?? (db = DbFactory.Open());
}
}
public Repository()
{
Db.DropAndCreateTable<T>();
}
public List<T> GetByIds(long[] ids)
{
return Db.Ids<T>(ids).ToList();
}
}
Run Code Online (Sandbox Code Playgroud)
然后在我的AppHost.Configure().我像这样注册依赖:
container.Register<IDbConnectionFactory>(c =>
new OrmLiteConnectionFactory(ConfigurationManager.
ConnectionStrings["AppDb"].ConnectionString, SqlServerDialect.Provider));
container.RegisterAutoWired<Repository<Todo>>().ReusedWithin(Funq.ReuseScope.None);
Run Code Online (Sandbox Code Playgroud)
但是当我运行我的应用程序时,它似乎是我DbFactory的null并且没有被正确注入,因为我得到一个Null Reference异常.
我有一个NancyFx应用程序,我在路径下设置了一个虚拟目录/photos.但是,当我浏览它时,我得到了404.我已经确定权限等..是正确的所以我想知道是否与NancyFx劫持请求并寻找在我的/photos路径下定义的路由有关吗?
我将数组传递给我的服务时遇到问题,它只识别数组中的第一个值:
这是我的请求对象:
[Route("/dashboard", "GET")]
public class DashboardRequest : IReturn<Dashboard>
{
public int[] EquipmentIds { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
以下是提出的请求:
http://localhost:9090/json/reply/DashboardRequest?EquipmentIds=1&EquipmentIds=2
Run Code Online (Sandbox Code Playgroud)
但是当我在服务中观察数组时,它只包含一个值,即1.
public object Get(DashboardRequest request)
{
// request.EquipmentIds.Length == 1;
// request.EquipmentIds[0] == 1;
}
Run Code Online (Sandbox Code Playgroud)
我所做的一个解决方案如下,看起来有点hacky?我认为在我的Request Object中指定它的意思是我得到一个强类型的Request Object?
var equipmentIds = Request
.QueryString["EquipmentIds"]
.Split(',')
.Select(int.Parse)
.ToList();
Run Code Online (Sandbox Code Playgroud) 我想知道是否可能有两个动作指向控制器中的同一个ActionResult,如下所示:
[HttpPost]
[ActionName("ManualSearch")]
[ActionName("AddProduct")]
public virtual ActionResult MyPostAction(MyModel model)
{
// do code...
}
Run Code Online (Sandbox Code Playgroud)
这样做的原因是因为我有2个视图,每个视图都以不同的方式处理动作,但它们都包含一个表单,基本上是做同样的事情,所以我想知道只是让这两个表单POST到同一个动作,就像我一样在上面尝试过,显然它不可能复制ActionName属性.
当我尝试手动向表中插入新行时,出现以下错误:
Cannot insert the value NULL into column 'VehicleID', table 'TestServer.Vehicles'; column does not allow nulls. INSERT fails.
The statement has been terminated.
Run Code Online (Sandbox Code Playgroud)
即使我在我的代码中设置了VehicleID,如下所示:
List<Vehicles> vehicleList = context.Vehicles.ToList();
if(vehicleList.Count == 0)
{
vehicle.VehicleID = 1;
}
else
{
vehicle.VehicleID = vehicleList.Last().VehicleID + 1;
}
context.Vehicles.Add(vehicle);
context.SaveChanges();
// Other code...
Run Code Online (Sandbox Code Playgroud)
我需要这样做的原因是因为在这个Action中,我实际上正在更新另一个模型,但我也想更新我的Vehicle模型,基于其他模型即时更新
我的VehicleID属性有[Key]数据注释集,这可能是原因吗?
每当我在Internet Explorer中选择一个元素时,它周围会出现虚线,几乎就像一个边框.反正有禁用此功能吗?
可以像这样使用LINQ OrderBy:
.OrderBy(x=>(x.SourceID == 3), (x.SourceID == 2), (x=>x.SourceID == 4), (x.SourceID == 1)).ToList();
Run Code Online (Sandbox Code Playgroud)
所以它会按顺序排列3,2,4,1?
我有以下POCO:
[Alias("Posts")]
public class Post : IReturn<Post>
{
[AutoIncrement]
[PrimaryKey]
public int PostId { get; set; }
public DateTime CreatedDate { get; set; }
[StringLength(50)]
public string CreatedBy { get; set; }
[StringLength(75)]
public string Title { get; set; }
public string Body { get; set; }
public int UpVote { get; set; }
public int DownVote { get; set; }
public bool IsPublished { get; set; }
public List<Comment> Comments { get; set; }
public List<Tag> Tags { get; …Run Code Online (Sandbox Code Playgroud)