小编Uth*_*imi的帖子

更改事件对动态生成的元素不起作用 - Jquery

我使用jquery Ajax动态生成dropdownList,生成的dropdown的id为specificationAttribute.我想为新标签生成添加事件生成(specificationAttribute),为此我在下面创建scriptwindow.load:

$(document).on('change', '#specificationattribute', function () {
    alert("Clicked Me !");
});
Run Code Online (Sandbox Code Playgroud)

但它不起作用.我尝试更多的方式click,live但我不能得到任何结果.

的jsfiddle

来自小提琴的代码:

$(window).load(function () {
  $("#specificationCategory").change(function () {
        var selected = $(this).find(":selected");
        if (selected.val().trim().length == 0) {
            ShowMessage('please selecet ...', 'information');
        }
        else {

            var categoryId = selected.val();
            var url = $('#url').data('loadspecificationattributes');

            $.ajax({
                url: url,
                data: { categoryId: categoryId, controlId: 'specificationattribute' },
                type: 'POST',
                success: function (data) {
                    $('#specificationattributes').html(data);
                },
                error: function (response) {
                    alert(response.error);

                } …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery

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

用户在控制器中为空,但在View中有值

我使用ASP.NET MVC 5Identityfor Authentication,我的问题是使用下面的代码:

User.Identity.IsAuthenticated
Run Code Online (Sandbox Code Playgroud)

User 是Null,但我在View Like下面使用了Above代码,它的工作正常,用户有价值.

  @if (User.Identity.IsAuthenticated)
            {...}
Run Code Online (Sandbox Code Playgroud)

什么事?

要做到这一点,我在谷歌上搜索并找到一种方法

protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    {
        base.Initialize(requestContext);
    }
Run Code Online (Sandbox Code Playgroud)

authentication asp.net-mvc identity

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

无法使用 Razor 在 foreach 中关闭标签 - ASP.NET MVC

我有一个div,每个div都有两个divs,如下所示:

<div class="col">
    <div class="item-c color1">..</div>
    <div class="item-c color2">..</div>
</div>
Run Code Online (Sandbox Code Playgroud)

我从数据库中读取数据,我想用一个foreach语句重复这个 div 。

我使用下面的代码,但我得到一个 Runtime Error

<div class="col">
@foreach (var item in Model)
{

    <div class="item-c  @("color" + index.ToString()) ">..</div>
    if (index % 2 == 0)
    {
        <text></div><div class="col"></text>
    }
    index++;
    if (index > 8) { index = 1; }
}
Run Code Online (Sandbox Code Playgroud)

我的结果应该是这样的: 在此处输入图片说明 我收到此错误:

遇到没有匹配开始标签的结束标签“div”

html asp.net-mvc razor

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

GetType Equal的方法为两个相同的类返回false - c#

我有一个类像:StoreDetail它继承自BaseEntity,我添加一个方法BaseEntity将类复制到另一个类,如下:

public abstract class BaseEntity
    {
 public void Copy(BaseEntity source, BaseEntity destination)
        {
            var destinationId = destination.Id;
            var sourceType = source.GetType();
            var destinationType = destination.GetType();
            if (sourceType.Equals(destinationType))
            {
                foreach (var field in sourceType.GetFields())
                {
                    var dstinationField = destinationType.GetField(field.Name);
                    if (dstinationField == null)
                        continue;
                    dstinationField.SetValue(destination, field.GetValue(source));
                }

                foreach (var field in sourceType.GetProperties())
                {
                    var dstinationField = destinationType.GetProperty(field.Name);
                    if (dstinationField == null)
                        continue;

                    dstinationField.SetValue(destination, field.GetValue(source, null), null);
                }
            }
            destination.Id = destinationId;
        }
  }
Run Code Online (Sandbox Code Playgroud)

首先,我用这一行检查两个对象的类型:

 var …
Run Code Online (Sandbox Code Playgroud)

c# reflection

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