我有一个购物车,其中包括以下内容:
我们的想法是,用户可以修改购物车中每个产品的数量,然后单击"更新"以提交更改.
你会如何使用MVC编程"更新"按钮?您是否将整个购物车包裹在一个回复自身的表格中,并以某种方式在FormCollection中找到数量值?这种方法的问题在于,由于"删除"按钮每个都以自己的形式存在,我现在将在页面上进行嵌套表单,我甚至不确定是否允许.
<% using (Html.BeginForm("Index", "Cart")) { %>
<table>
<tr>
<th> </th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<input name="qty" type="text" value="<%=item.Quantity%>" maxlength="2" />
<% using (Html.BeginForm("RemoveOrderItem", "Cart")) { %>
<%= Html.Hidden("ShoppingCartItemID", item.ShoppingCartItemID) %>
<input name="add" type="submit" value="Remove" />
<%} %>
</td>
</tr>
<% } %>
</table>
<input name="update" type="submit" value="Update" />
<%} %>
Run Code Online (Sandbox Code Playgroud)
如何将底部输入合并到此表单中?
我有以下代码:
public void GetJson()
{
RestRequest request = new RestRequest(Method.GET);
var data = Execute<Dictionary<string, MyObject>>(request);
}
public T Execute<T>(RestRequest request) where T : new()
{
RestClient client = new RestClient(baseUrl);
client.AddHandler("text/plain", new JsonDeserializer());
var response = client.Execute<T>(request);
return response.Data;
}
Run Code Online (Sandbox Code Playgroud)
问题是有时响应将是一个空的json数组[].当我运行此代码时,我得到以下异常:无法将类型为'RestSharp.JsonArray'的对象强制转换为'System.Collections.Generic.IDictionary`2 [System.String,System.Object]'.
有没有办法优雅地处理这个?
我目前正在使用Ninject(2.2.1.4)和Ninject.Extensions.Wcf(2.2.0.4)和我的WCF服务.我想升级到Ninject(3.0.0.15)和Ninject.Extensions.Wcf(3.0.0.5),看起来我不能再使用我当前的方法了.任何人都可以向我指出一些样本或帖子,了解如何使用WCF项目获得最新版本的Ninject.
我目前的做法:
我写了一个模块:
public class NinjectDependencyResolver : NinjectModule
{
public override void Load()
{
// Declare bindings
}
}
Run Code Online (Sandbox Code Playgroud)
我将Factory属性添加到我的.svc文件中
Factory="Ninject.Extensions.Wcf.NinjectServiceHostFactory"
Run Code Online (Sandbox Code Playgroud)
我在WCF项目中添加了一个Global.asax
public class Global : NinjectWcfApplication
{
protected override IKernel CreateKernel()
{
return new StandardKernel(new NinjectDependencyResolver());
}
}
Run Code Online (Sandbox Code Playgroud)
现在我可以修改我的服务中的默认构造函数并使用构造函数注入.
关于如何升级的任何指示都表示赞赏.
谢谢
我有以下域模型:
public class Playlist
{
public long Id { get; set; }
public string Title { get; set; }
public virtual ICollection<Song> Songs { get; set; }
}
public class Song
{
public long Id { get; set; }
public string Name { get; set; }
public virtual Playlist Playlist { get; set; }
public virtual ICollection<Catalog> Matches { get; set; }
}
public class Catalog
{
public long Id { get; set; }
public string Title { get; set; …Run Code Online (Sandbox Code Playgroud) design-patterns domain-driven-design data-transfer-objects ddd-repositories asp.net-mvc-3
我有以下型号:
public class List
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual ICollection<ListRules> ListRule { get; set; }
}
public class ListRule
{
public virtual int Id { get; set; }
public virtual List List { get; set; }
public virtual ICollection<List> Lists { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
List可以有许多ListRules.ListRule必须属于一个列表.ListRule还可以包含0,1或多个与之关联的列表.
我尝试了以下绑定:
modelBuilder.Entity<ListRule>()
.HasRequired(x => x.List)
.WithMany(x => x.ListRule)
.Map(x => x.MapKey("ListId"));
modelBuilder.Entity<ListRule>()
.HasMany(x => x.Lists)
.WithMany()
.Map(x => {
x.MapLeftKey("ListRuleId"); …Run Code Online (Sandbox Code Playgroud) 我一直在做这方面的研究,我找不到直接的答案.
是否有一些存储在容器中的cookie,我无法使用Response.Cookies集合?如何在使用这些对象的请求之间处理cookie?有些饼干存放在容器中但不存储在其他容器中吗?
asp.net asp.net-mvc httpwebrequest system.net.httpwebrequest
使用 Visual Studio 时,可以轻松地从我自己编写的类中提取接口。我右键单击该类并选择“重构”,然后选择“提取接口”。
让我们假设我想创建一个 ConfigurationManager 包装器并围绕它编写一些测试。一种快速的方法是从 ConfigurationManager 中提取接口,方法是右键单击它,然后“转到定义”,然后从类内部选择“重构”,然后选择“提取接口”。然后我只需创建我的包装类,从新创建的接口继承,然后实现它,我的包装类就有了一个很好的起点。
但是,从任何 .NET 系统类中提取接口是不可能的,可能是因为它只是有关类的元数据,而不是类本身(或者我做错了)。
有没有一种简单的方法可以完成我想要完成的任务?我想确保我不会浪费时间输入不需要输入的内容。
谢谢
我在Global.aspx中有以下代码
protected override void OnApplicationStarted()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
RegisterAllControllersIn(Assembly.GetExecutingAssembly());
}
protected override IKernel CreateKernel()
{
return new StandardKernel(new ServiceModule());
}
Run Code Online (Sandbox Code Playgroud)
我还有以下Ninject模块:
internal class ServiceModule : NinjectModule
{
public override void Load()
{
Bind<IProductService>().To<ProductService>().InRequestScope();
}
}
Run Code Online (Sandbox Code Playgroud)
我还有一个基本控制器:
public class BaseController : Controller
{
[Inject]
public IProductService ProductService
{
get;
set;
}
}
Run Code Online (Sandbox Code Playgroud)
这段代码有效.我遇到的问题是我想从基本控制器中删除inject属性,并在Ninject ServiceModule中指定它.换句话说,我如何在ServiceModule中编写绑定规则,告诉Ninject将ProductService注入基本控制器的属性?
如果我删除该属性,我将得到NullReferenceException.
我目前正在使用TopShelf和Ninject来创建Windows服务.我有以下代码使用TopShelf设置Windows服务:
static void Main(string[] args)
{
using (IKernel kernel = new StandardKernel(new NinjectDependencyResolver()))
{
Settings settings = kernel.Get<Settings>();
var host = HostFactory.New(x =>
{
x.Service<BotService>(s =>
{
s.ConstructUsing(name => new BotService(settings.Service.TimeInterval));
s.WhenStarted(ms => ms.Start());
s.WhenStopped(ms => ms.Stop());
});
x.RunAsNetworkService();
x.SetServiceName(settings.Service.ServiceName);
x.SetDisplayName(settings.Service.DisplayName);
x.SetDescription(settings.Service.Description);
});
host.Run();
}
}
Run Code Online (Sandbox Code Playgroud)
这是Windows服务完成所有工作背后的对象:
public class BotService
{
private readonly Timer timer;
public BotService(double interval)
{
this.timer = new Timer(interval) { AutoReset = true };
this.timer.Elapsed += (sender, eventArgs) => Run();
}
public void Start()
{
this.timer.Start(); …Run Code Online (Sandbox Code Playgroud) windows-services ninject topshelf ef-code-first entity-framework-4.1
我正在尝试使用EF代码迁移创建索引.该索引看起来像:
CREATE INDEX [IX_RatingId_CreatedAt] ON [Users]
(
[RatingId] ASC,
[CreatedAt] ASC
)
INCLUDE (Id, Email, DomainId)
Run Code Online (Sandbox Code Playgroud)
我到目前为止的代码是:
CreateIndex("Users",
new string[] { "RatingId", "CreatedAt" },
false,
"IX_RatingId_CreatedAt"
);
Run Code Online (Sandbox Code Playgroud)
这将为我创建索引,但不包括列.CreateIndex方法有一个覆盖,它接受一个名为anonymousArguments的东西.我真的找不到关于它的那么多信息,所以我尝试了类似的东西:
CreateIndex("Users",
new string[] { "RatingId", "CreatedAt" },
false,
"IX_RatingId_CreatedAt",
new { INCLUDE = "(Id, Email, DomainId)" });
Run Code Online (Sandbox Code Playgroud)
没有例外但它没有用.
是否可以使用CreateIndex方法创建上述索引,还是必须使用Sql方法在我的迁移中写出T-SQL?如何正确使用匿名参数?
entity-framework ef-code-first ef-migrations entity-framework-4.3