小编Dmi*_*try的帖子

DropDownListFor - 不选择"Selected"值

关于DropDownListFor不选择"已选择"值的另一个问题.这是代码:

模型:

public class CreateEditAccountModel
{
    [Required]
    [Display(Name = "Permission")]
    public int PermissionId { get; set; }
    public IEnumerable<SelectListItem> Permissions { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

控制器:

[HttpGet]
[Authorize]
public ActionResult EditAccount(int id)
{
    CreateEditAccountModel model = new CreateEditAccountModel();
    model.Permissions = PermissionsAll();
    return View("CreateEditAccount", model);
}
Run Code Online (Sandbox Code Playgroud)

此时,如果我在返回线上放置一个断点,则model.Permissions包含IEnumerable<SelectListItem>具有多个项目且只有一个的正确对象Selected = true.

视图:

@using (Html.BeginForm())
{
    @Html.DropDownListFor(m => m.PermissionId, Model.Permissions)
}
Run Code Online (Sandbox Code Playgroud)

呈现:

<select id="PermissionId" name="PermissionId">
    <option value="">-- Select --</option>
    <option value="1">Permission one</option>
    <option value="2">Permission …
Run Code Online (Sandbox Code Playgroud)

html.dropdownlistfor asp.net-mvc-3

14
推荐指数
1
解决办法
2万
查看次数

中文(.cn)api调用.com AutocompletionService导致失败

为了在中国自动完成工作,我引用了中文Google Maps Api,如文档中所述.

当它被调用以获得自动完成结果时,我看到它正确地发出请求:http: //maps.google.cn/maps/api/js/AuthenticationService.Authenticate?...

...但随后拨打电话:https: //maps.googleapis.com/maps/api/js/AutocompletionService.GetPredictions?...

...由于该域名在中国被封锁,因此在中国使用网站时无法完成.

请参阅plunker演示(按F12,打开"网络"选项卡,并在输入时键入请求).显然,带有plunkr链接的SO问题需要代码,所以这里是对我使用的脚本的引用:

<script type="text/javascript" src="http://maps.google.cn/maps/api/js?libraries=places&sensor=false"></script>
Run Code Online (Sandbox Code Playgroud)

以下是显示问题的屏幕截图: 使用.cn脚本时调用错误的服务

这是一个提交给谷歌的错误报告,显然对他们来说都很好.

难道我做错了什么?有人可以确认他们看到的行为和我一样吗?

autocomplete google-maps-api-3

7
推荐指数
0
解决办法
920
查看次数

Angular - 在child指令的控制器中获取父指令的控制器(不是链接函数)

我知道如何directive在子指令的link函数中获取父控制器.
但是,我宁愿避免使用link函数(和$scope所有在一起),并controller在指令的功能下拥有我的所有代码.

angular.directive('parent', function(){
    return {
        templateUrl: '/parent.html',
        scope: true,
        bindToController: true,
        controllerAs: 'parentCtrl',
        controller: function(){
            this.coolFunction = function(){
                console.log('cool');
            }
        }
    }
});

angular.directive('child', function(){
    return {
        templateUrl: '/child.html',
        require: '^parent',
        scope: true,
        bindToController: true,
        controllerAs: 'childCtrl',
        controller: function() {
            // I want to run coolFunction here.
            // How do I do it?
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏!

angularjs angularjs-directive angularjs-controller

7
推荐指数
1
解决办法
2047
查看次数

MVC HtmlHelper与FluentValidation 3.1:获取ModelMetadata IsRequired的麻烦

我创建了一个HtmlHelper for Label,如果需要关联字段,则在该Label的名称后面放置一个星号:

public static MvcHtmlString LabelForR<TModel, TValue>(
        this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression)
{
    return LabelHelper(
        html,
        ModelMetadata.FromLambdaExpression(expression, html.ViewData),
        ExpressionHelper.GetExpressionText(expression),
        null);
}

private static MvcHtmlString LabelHelper(HtmlHelper helper, ModelMetadata metadata, string htmlFieldName, string text)
{
    ... //check metadata.IsRequired here
    ... // if Required show the star
}
Run Code Online (Sandbox Code Playgroud)

如果我在我的ViewModel中的属性上使用DataAnnotations和slap [Required],我的私有LabelHelper中的metadata.IsRequired将等于True,并且一切都将按预期工作.

但是,如果我使用FluentValidation 3.1并添加一个简单的规则:

public class CheckEmailViewModelValidator : AbstractValidator<CheckEmailViewModel>
{
    public CheckEmailViewModelValidator()
    {
        RuleFor(m => m.Email)
            .NotNull()
            .EmailAddress();
    }
}
Run Code Online (Sandbox Code Playgroud)

...在我的LabelHelper metadata.IsRequired将被错误地设置为false.(验证器有效:你不能提交空字段,它需要像电子邮件一样).
其余元数据看起来正确(例如:metadata.DisplayName ="Email").
理论上,如果使用Rule .NotNull(),FluentValidator会在属性上使用RequiredAttribute.

对于参考:我的ViewModel:

[Validator(typeof(CheckEmailViewModelValidator))]
public class CheckEmailViewModel
{
    //[Required] …
Run Code Online (Sandbox Code Playgroud)

html-helper modelmetadata fluentvalidation asp.net-mvc-3 isrequired

6
推荐指数
1
解决办法
1268
查看次数

Angular - 基于$ stateParams更改路由状态更改的css类

我在布局页面中有一个div:

<div class="{{$root.containerClass}}">...</div>
Run Code Online (Sandbox Code Playgroud)

有两种路线状态:

.state('controllerAction', {
    url: '/:controller/:action',
    templateUrl: function($stateParams) {
         return $stateParams.controller + '/' + $stateParams.action;
    },
    controllerProvider: function($stateParams) {
         return $stateParams.controller + $stateParams.action + 'Controller';
    },
    onEnter: function($rootScope, $stateParams) {
        $rootScope.containerId = $stateParams.controller.toLowerCase() + '-index';
    }
})
.state('controller', {
    url: '/:controller',
    templateUrl: function($stateParams) {
         return $stateParams.controller + '/index';
    },
    controllerProvider: function($stateParams) {
         return $stateParams.controller + 'Controller';
    },
    onEnter: function($rootScope, $stateParams) {
        $rootScope.containerId = $stateParams.controller.toLowerCase() + '-index';
    }
});
Run Code Online (Sandbox Code Playgroud)

我想class在路线改变时改变$stateParams.有了上面的代码,它的变化,但只有到containerClass了的以前的路线.

任何帮助表示赞赏.

angularjs angular-ui-router

6
推荐指数
1
解决办法
1万
查看次数

TempData Wrapper

因为我一遍又一遍地使用相同的TempData键,所以我想更容易跟踪这些键.如果最终我能写出这样的东西会很棒:

MyTempData.Message = "my message";
Run Code Online (Sandbox Code Playgroud)

代替

TempData["Message"] = "my message";
Run Code Online (Sandbox Code Playgroud)

.net c# tempdata asp.net-mvc-3

5
推荐指数
2
解决办法
2926
查看次数

如何设置htmlHelpers的项目,以便它生成两个dll - 对于mvc3和mvc4?

我有一个html帮助程序库作为一个单独的项目.现在它引用system.web.mvc了版本4.

如果我尝试在使用mvc3的项目中使用此库,则在尝试使用帮助程序时会抛出错误:

Compiler Error Message: CS1705: Assembly 'MyHtmlHelpers, Version=3.7.4.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
Run Code Online (Sandbox Code Playgroud)

我知道我需要使用system.web.mvc引用的版本3 构建我的助手项目,以便它与mvc3项目兼容.我不希望有两个具有相同代码的项目,只是system.web.mvc引用的差异.

问题在标题中.任何帮助表示赞赏.

c# asp.net-mvc asp.net-mvc-3 asp.net-mvc-4

5
推荐指数
1
解决办法
83
查看次数

AngularJs从响应动态下载

我根据斯科特的答案撰写了一份指令.你会这样使用它:

<button class="btn btn-success"
        download-response="getData()"
        download-success="getDataSuccess()"
        download-error="getDataError()"
        download-name="{{name}}.pdf"
        download-backup-url="/Backup/File.pdf">
    Save
</button>
Run Code Online (Sandbox Code Playgroud)

问题:下面的代码引发错误TypeError: Invalid calling objectIE11第一方法(行:saveBlob(blob, filename);).即使它回归到其他下载方法,我的理解是saveMethod1应该工作IE11.

这是代码:

'use strict';

// directive allows to provide a function to be executed to get data to be downloaded
// attributes:
// download-response - Required. Function to get data. It must return a promise. It must be declared on the $scope.
// download-success - Optional. Function to be executed if download-response function was …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs internet-explorer-11

5
推荐指数
1
解决办法
4116
查看次数

Angular - UI路由器 - 嵌套状态 - 浏览器后退按钮无法按预期工作

我有一个场景,我有以下嵌套状态结构:

root
  root.item1
  root.item2
Run Code Online (Sandbox Code Playgroud)

root州有显示,在孩子的状态设置一些变量的模板.它还需要首先运行,因为它具有确定将加载哪个子状态的逻辑.

如果root确定root.item2需要加载事件流,则:

exec root -> redirect to root.item2 -> exec root.item2
Run Code Online (Sandbox Code Playgroud)

现在,如果此时我们重定向到root.item1他们按下浏览器后退按钮,我希望被重定向到root.item2,但它看起来像url被清除,你根本看不到任何子状态.

这是一个显示问题的Plunker示例.

在Plunker中重现问题的步骤:

  1. 让它加载 root.item2
  2. 点击 Go to Detail 1
  3. 注意你在 root.item1
  4. 单击浏览器后退按钮
  5. 注意你不在 root.item2

将提交的问题提交到UI路由器的Gihub页面.希望有一些帮助来自那里.

任何帮助表示赞赏.


显示问题的代码:

angular
.module('historyApp', [
  'ui.router'
]) 
.config(['$stateProvider', '$urlRouterProvider',
  function($stateProvider, $urlRouterProvider) {

    $stateProvider
      .state('root', {
        url: '/',
        template: '<h1>Parent</h1> <div>{{vm.title}}</div> <div ui-view></div>',
        controller: function($scope, $state){
            $scope.vm = { title: '' };
            // some conditional login …
Run Code Online (Sandbox Code Playgroud)

angularjs angular-ui-router

5
推荐指数
1
解决办法
2730
查看次数

在 ajax 调用特定操作期间跳过 RenewTicketIfOld

我使用setIntervalajax 调用来每分钟检查新消息。这个调用扩展了身份验证cookie(因为我将slidingExpiration设置为true),因此身份验证永远不会过期。

这个问题有类似的问题,但解决方案是针对 .net 类项目的,我不知道如何将其应用到我的 MVC 项目中。

如果解决方案采用属性的形式,就像[DoNotExtendAuthentication]我可以执行操作一样,那就太好了,但任何帮助都会受到赞赏。

ajax forms-authentication asp.net-mvc-4

3
推荐指数
1
解决办法
709
查看次数

错误:共享内存不足

我有一个查询,可以插入给定数量的测试记录。看起来像这样:

CREATE OR REPLACE FUNCTION _miscRandomizer(vNumberOfRecords int)
RETURNS void AS $$
declare
    -- declare all the variables that will be used
begin
    select into vTotalRecords count(*) from tbluser;
    vIndexMain := vTotalRecords;

    loop
        exit when vIndexMain >= vNumberOfRecords + vTotalRecords;

        -- set some other variables that will be used for the insert
        -- insert record with these variables in tblUser
        -- insert records in some other tables
        -- run another function that calculates and saves some stats regarding inserted records

        vIndexMain …
Run Code Online (Sandbox Code Playgroud)

memory postgresql loops

3
推荐指数
1
解决办法
2万
查看次数

所有按长度的 HtmlAgilityPack 子串

我有带有嵌套元素的 html(主要是divp元素)我需要返回相同的 html,但由给定数量的字母组成子字符串。显然字母数不应该通过html标签枚举,而应该只计算每个html元素的InnerText的字母。Html 结果应保留正确的结构 - 任何结束标记以保持有效的 html。

样本输入:

<div>
    <p>some text</p>
    <p>some more text some more text some more text some more text some more text</p>
    <div>
        <p>some more text some more text some more text some more text some more text</p>
        <p>some more text some more text some more text some more text some more text</p>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

鉴于int length = 16输出应如下所示:

<div>
    <p>some text</p> // 9 characters in the InnerText here
    <p>some …
Run Code Online (Sandbox Code Playgroud)

c# html-agility-pack

1
推荐指数
1
解决办法
1838
查看次数