我正在使用Visual Studio 2010/ASP.net MVC 3和Razor View Engine.我使用Internet应用程序模板创建了一个新项目.我需要做什么才能让Intellisense工作?
我想从我的控制器返回一个EditorTemplate作为Partial View.
我目前在做:
public ActionResult Create([Bind(Prefix="Create")]CreateViewModel model)
{
    return PartialView("~/Views/Shared/EditorTemplates/Template.cshtml", model);
}
Run Code Online (Sandbox Code Playgroud)
问题是,在我这样做之后,Create_前缀远离我的观点.有没有办法将编辑器模板作为局部视图返回并保留前缀?
Index.cshtml @model IndexViewModel
@using(Html.BeginForm("Create"))
{
    @Html.EditorFor(m => m.Create, "Template")
    <input type="submit" value="Save" />
}
Run Code Online (Sandbox Code Playgroud)
我正在通过AJAX调用提交此表单.当我最初调用EditorFor时,所有字段都有一个前缀Create_.但是,在我提交表单并返回此PartialView后,前缀将丢失.
我在我的数据库上有全文搜索.
是否可以在单词的中间搜索某些文本?
例如,我有一个包含以下文本的列描述:
Revolution
Run Code Online (Sandbox Code Playgroud)
是否有可能搜索"EVO"并让它在"革命"这个词中找到它,或者我是不是喜欢这样做:
SELECT * FROM Table WHERE Description LIKE '%EVO%'
Run Code Online (Sandbox Code Playgroud)
是否有与上述查询相当的FTS?
编辑
 
我想清楚说明我想要问的内容,因为看起来有些人可能会感到困惑.我相信 SQL Server FTS只能在单词的开头搜索(前缀搜索).所以,如果我查询:
SELECT * FROM Table WHERE CONTAINS(Description, '"Revo*"')
Run Code Online (Sandbox Code Playgroud)
然后它会找到革命这个词.我想知道是否有可能在单词的MIDDLE中搜索某些内容.不是最后的.不是一开始.从它看起来这是不可能的,这是有道理的,因为SQL服务器如何索引这个,但我只是想确定.
每个视图或每个控制器操作一个ViewModel是一个更好的主意吗?
例:
public ProjectController : Controller
{
    public ActionResult Edit(int id)
    {
        var project = ...;
        return View(new ProjectEditViewModel(project));
    }
    [HttpPost]
    public ActionResult Edit(ProjectEditViewModel model)
    {
    }
    **OR**
    [HttpPost]
    public ActionResult Edit(Project model)
    {
    }
    [HttpPost]
    public ActionResult Edit(ProjectEditPostViewModel model)
    {
    }
}
Run Code Online (Sandbox Code Playgroud)
以下是三个选项,哪个最好?
我正在使用Entity Framework 4.2(代码优先)来访问我的数据库.我假设如果我查询使用SingleOrDefault它的实体只会查询数据库是否实体尚未被跟踪,但事实并非如此.Find另一方面,该方法似乎确实这样做了.问题Find是它似乎不允许我加载相关数据.
有没有办法使用该Find方法,但也急切加载数据?例如,我想加载一本书及其所有评论:
// Load book from the database
Book book = context.Books.Find(1); 
context.Entry<Book>(book).Collection<Review>.Load(); // Book.Reviews is now populated
// Load book from the change tracker
// This will include all Reviews as well
Book book2 = context.Books.Find(1);
Run Code Online (Sandbox Code Playgroud)
随着SingleOrDefault我可以加载评论时,我得到使用包括书:
// Load book + reviews from the database
Book book = Book.Include("Reviews").SingleOrDefault(b => b.Id == 1);
// Doing the same thing again requeries the database
Book book2 = Book.Include("Reviews").SingleOrDefault(b => …Run Code Online (Sandbox Code Playgroud) 我有一个使用Ninject依赖注入的现有MVC应用程序.我安装了Ninject.MVC3 nuget包,它在我的App_Start中创建了一个名为NinjectWebCommon的类,它完全隔离了内核并注册了我的所有绑定:
public static void Start()
{
    DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
    DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
    bootstrapper.Initialize(CreateKernel);
}
private static IKernel CreateKernel()
{
    var kernel = new StandardKernel();
    kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
    kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
    RegisterServices(kernel);
    return kernel;
}
private static void RegisterServices(IKernel kernel)
{
    kernel.Bind<IFoo>().To<Foo>();
}
Run Code Online (Sandbox Code Playgroud)
我们有一个新的要求,我们认为SignalR能够满足,所以我们将SignalR 2 nuget包安装到项目中.我创建了一个Hub并对如何在项目中实现依赖注入进行了一些搜索,并找到了一篇建议创建SignalRDependencyResolver的文章.http://www.asp.net/signalr/overview/signalr-20/extensibility/dependency-injection
本文让您在Startup.cs文件中创建一个内核,用于在OWIN中注册SignalR:
public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        var kernel = new StandardKernel();
        var resolver = new NinjectSignalRDependencyResolver(kernel);
        kernel.Bind<IStockTicker>()
            .To<Microsoft.AspNet.SignalR.StockTicker.StockTicker>()  // Bind to StockTicker.
            .InSingletonScope();  // Make it a singleton object.
        kernel.Bind<IHubConnectionContext>().ToMethod(context =>
            resolver.Resolve<IConnectionManager>().GetHubContext<StockTickerHub>().Clients …Run Code Online (Sandbox Code Playgroud) 如果我有以下全文搜索查询:
SELECT *
FROM dbo.Product
   INNER JOIN CONTAINSTABLE(Product, (Name, Description, ProductType), 'model') ct
      ON ct.[Key] = Product.ProductID
Run Code Online (Sandbox Code Playgroud)
是否可以称量正在搜索的列?
例如,我更关心"名称"列中出现的单词模型,而不是"描述"或"ProductType"列.
当然,如果单词在所有3列中,那么我希望它排名高于它在名称列中的排名.如果只出现在Name/Product/ProductType中,是否有任何方法可以使行排名更高?
谷歌浏览器似乎在溢出字段集内的内容时出现错误.
这是一个证明问题的jsfiddle:http://jsfiddle.net/Dismissile/Lnm42/
如果你查看页面,你会看到当你在一个fieldset中有一个容器,并且容器已overflow: auto设置,并且该容器的内容将水平溢出时,fieldset实际上是扩展而不是使用滚动条:
<fieldset class="parent">
    <div class="child">
        <div class="grandchild">
            asdf
        </div>
     </div>
</fieldset>
<div class="parent">
    <div class="child">
        <div class="grandchild">
            asdf
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.parent {
    border: 1px solid green;
    padding: 20px;
    margin: 20px;
}
.child {
    border: 1px solid red;
    padding: 20px;
    overflow: auto;
}
.grandchild {
    border: 1px solid #ccc;
    width: 2000px;
    padding: 10px;
}
Run Code Online (Sandbox Code Playgroud)
我是否可以使用CSS黑客/修复程序,以便在Chrome中的字段集内部内容正常溢出?
我在另一篇SO帖子中看到了这段代码:使用ASP MVC的jQuery UI Autocomplete
    $("#CustomerID").autocomplete({
        source: function(request, response) {
            $.ajax({
                type: "POST",
                url: "/customer/search",
                dataType: "json",
                data: {
                    term: request.term
                },
                error: function(xhr, textStatus, errorThrown) {
                    alert('Error: ' + xhr.responseText);
                },
                success: function(data) {
                    response($.map(data, function(c) {
                        return {
                            label: c.Company,
                            value: c.ID
                        }
                    }));
                }
            });
        },
        minLength: 2,
        select: function(event, ui) {
            alert('Select');
        }
    });
Run Code Online (Sandbox Code Playgroud)
除了成功功能,我理解一切.我知道map正在采用数组并将每个值映射到具有label和value属性并返回新数组的新对象,但我不确定response()的作用.
在我的MVC应用程序中,我有几个不同的角色:管理员,普通用户等等.
我知道我可以通过Authorize属性将安全性应用于我的控制器:
[Authorize(Roles="Admin")]
public ActionResult Create()
{
    return View();
}
Run Code Online (Sandbox Code Playgroud)
但我还需要对视图应用一些安全性,以便不将View的某些部分显示给某些角色:
@if( User.IsInRole("Admin") )
{
    @Html.ActionLink("Create", "Create")
}
Run Code Online (Sandbox Code Playgroud)
以上述方式执行此操作是否更好,或者在ViewModel中处理此类安全性:
public ActionResult Index()
{
    var model = new IndexViewModel();
    model.CanCreate = User.IsInRole("Admin");
    return View(model);
}
View:
@( Model.CanCreate )
{
    @Html.ActionLink("Create", "Create")
}
Run Code Online (Sandbox Code Playgroud)
第二种方法与第一种方法相比是否有任何好处,还是只是偏好?
asp.net-mvc ×4
c# ×3
.net ×2
jquery ×2
razor ×2
sql-server ×2
css ×1
html ×1
intellisense ×1
javascript ×1
ninject ×1
response ×1
signalr ×1