小编Nic*_*ick的帖子

使用ASP.NET MVC 3中的HtmlHelper在表单标记中嵌套多个标签和输入

如何在ASP.NET MVC3中使用HtmlHelper在窗体标记内嵌套多个标签和输入?

我的代码如下:

public static string GenerateFormForContact(this HtmlHelper helper, string method, string action, bool includeMailTag)
{
    //form tag
    TagBuilder form = new TagBuilder("form");
    form.Attributes.Add("action", action);
    form.Attributes.Add("method", method);

    //label and input tag

    TagBuilder labelClientName = new TagBuilder("label");
    labelClientName.Attributes.Add("for", "clientName");
    TagBuilder inputClientName = new TagBuilder("input");
    inputClientName.Attributes.Add("name", "clientName");
    inputClientName.Attributes.Add("type", "text");
    inputClientName.Attributes.Add("placeholder", "Your name");
    inputClientName.Attributes.Add("required", "required");

    //how to insert inside form

    TagBuilder labelEmailName = new TagBuilder("label");
    labelEmailName.Attributes.Add("for", "emailName");
    TagBuilder inputEmailName = new TagBuilder("input");
    inputEmailName.Attributes.Add("name", "emailName");
    inputEmailName.Attributes.Add("type", "email");
    inputEmailName.Attributes.Add("placeholder", "Your mail");
    inputEmailName.Attributes.Add("required", "required");

    //how to …
Run Code Online (Sandbox Code Playgroud)

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

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

在C#对象中实现动态属性的最佳方法是什么?

我有许多类对象,每个对象都需要一个URL字段,该字段总是以相同的方式通过参数格式化,这是TypeId该类的另一个属性.

什么是抽象以此为动力性的最好方式,使URL字段是基于生成TypeIdItemId从类属性.

我可以想到很多方法可以做到这一点,但想知道推荐的做法是什么.

示例如下:

public class MyObject
{
    public int Id { get; set; }
    public string URL
    {
        get
        {
            if (TypeId == 3)
            {
                return "/do/this/" + ItemId;
            }
            if (TypeId == 5)
            {
                return "/do/that/" + ItemId;
            }
            return "#";
        }
    }
    public int ItemId { get; set; }
    public int TypeId { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

c#

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

在设备上测试iOS应用程序时出现RestKit错误

在从Apple安装我的配置文件后尝试测试我的iPhone应用程序时,我收到了很多"sematic问题"错误.

它在开发期间工作得很好,但是自从我设置配置文件后,每次尝试构建时都会收到以下错误(选择物理设备时为80,使用模拟器时为10):

RKRequest.h: error: Semantic Issue: Redefinition of 'RKRequestMethod' 
RKRequest.h: error: Semantic Issue: Redefinition of enumerator 'RKRequestMethodPOST' 
...
Run Code Online (Sandbox Code Playgroud)

我大约一个月前从它的git存储库中检索了RestKit的版本,直到现在它一直运行良好.

以下是错误详细信息的示例:

In file included from /Users/nick/Library/Developer/Xcode/DerivedData/MyApp-
bpcvkhxzjupqmibdvvipchdfecpi/Build/Products/Debug-
iphoneos/include/RestKit/CoreData/../ObjectMapping/../Network/RKClient.h:21:
Run Code Online (Sandbox Code Playgroud)

我已经尝试清除此目录,但问题仍然存在,并在下面包含了一个屏幕截图:

在此输入图像描述

这是一个如何在应用程序中使用RestKit的示例:

MyViewController.h

#import <RestKit/RestKit.h>
#import <RestKit/CoreData/CoreData.h> 

@interface MyViewController : UIViewController<RKObjectLoaderDelegate, MFMailComposeViewControllerDelegate, UIActionSheetDelegate, SelectTranslationDelegate>
...
Run Code Online (Sandbox Code Playgroud)

MyViewController.m

@interface MyViewController()
{
}
@end
...

@implementation MyViewController
...
Run Code Online (Sandbox Code Playgroud)

我的链接库

在此输入图像描述

有没有人对这可能是什么有任何建议?

xcode restkit

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

在正则表达式中使特殊字符可选

我有以下要求:

密码必须是6-18个字符,并且至少包含一个字母和一个数字.允许使用@,%,&等#等特殊字符.

我创造了这个:

^.*(?=.{6,18})(?=.*\d)(?=.*[A-Za-z])(?=.*[@%&#]).*$
Run Code Online (Sandbox Code Playgroud)

但是它也接受像_这样的其他特殊字符,它要求@%&#中的一个特殊字符必须在字符串中.我想让这个可选.意味着如果用户输入其中一个特殊字符,则字符串应该有效,但如果用户没有输入这些字符,那么它不应该是无效的.如果用户输入任何其他特殊字符,则字符串应无效.

regex asp.net-mvc-3

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

仅从字符串末尾获取标点符号

我正在寻找一个C#片段来删除和存储字符串末尾的任何标点符号.

例:

  • 测试!会回来的!
  • 测试;; 会回来;;
  • 测试?:?会回来吗?:?

  • !!测试!?!会回来的!?!

我现在有一个相当笨重的解决方案,但想知道是否有人可以提出一个更简洁的方法来做到这一点.

我的puncutation列表是

new char[] { '.', ':', '-', '!', '?', ',', ';' })
Run Code Online (Sandbox Code Playgroud)

c#

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

LINQ表达式只提取两个单词短语

我有一个(对象)列表,对象中有一个属性作为字符串.

此属性始终包含单个单词,并且希望成对循环遍历所有顺序组合,例如:

  • 字1
  • WORD2
  • WORD3
  • word4
  • 的word5

我正在尝试编写LINQ,这将允许我以下列格式迭代数据:

  • word1 [space] word2
  • word2 [space] word3
  • word3 [space] word4
  • word4 [space] word5

任何人都可以提出最有效的方法.

我现在有一堆条件IF语句,我想删除.

c# linq

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

将<div>定位在无序列表中时的垂直对齐

我在一个<ul>元素中添加了一个搜索框作为列表项,如下所示:

<nav id="notifications-menu">
    <ul id="display-inline-block">
        <li><a class="normal calendar" onclick="showUserCalendar('/', false);" href="#">My Calendar</a></li>
        <li><a class="normal calendarteam" onclick="showTeamCalendar('/', false);" href="#">Team Calendar</a></li>

        <li><div id="global-search-wrapper">
            <input type="text" class="global-search-box" name="s" value="type search term..." />
            <input type="image" src="/images/general/blank.gif" class="global-search-submit" value="" />
        </div></li>
    </ul>
</nav>
Run Code Online (Sandbox Code Playgroud)

当应用以下CSS时,我得到以下输出.我想让列表项文本中心对齐(垂直):

在此输入图像描述

nav#notifications-menu  { 
    font-family: 'Adelle', sans-serif;
    float:right;
    height: 52px; 
    width:600px;
    min-width:300px;
    padding: 0px 18px 0px 0px;
    text-align:right;
    font-size:13px;
}


nav#notifications-menu #display-inline-block,
nav#notifications-menu #display-inline-block li {
    /* Setting a common base */
    margin: 0;
    padding: 0;

}

nav#notifications-menu #display-inline-block li { …
Run Code Online (Sandbox Code Playgroud)

html css markup css3

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

为什么是C#方法生成的重复随机字符串

以下方法生成具有给定长度的随机字符串.

连续执行两次时,会给出相同的字符串.有人能说清楚为什么会这样吗?

 public static string GenerateRandomString(int size, bool lowerCase)
        {
            StringBuilder builder = new StringBuilder();
            Random random = new Random();
            char ch;
            for (int i = 0; i < size; i++)
            {
                ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
                builder.Append(ch);
            }
            if (lowerCase)
                return builder.ToString().ToLower();
            return builder.ToString();
        }
Run Code Online (Sandbox Code Playgroud)

c#

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

LINQ选择查询总是产生真值

当我点击以下行时,无论"本地"是否出现在连接Roles表中,我总是收到一个真值.

if (objUserRoles.Select(x => (x.Role.Role1 == "local")).Count() > 0)
Run Code Online (Sandbox Code Playgroud)

我的语法是否正确?

c# linq

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

简单的LINQ to Entities更新抛出'Timeout expired'

下面的简单方法是抛出超时错误,我无法弄清楚为什么会这样.这可以连续多次执行,我想知道这可能是原因吗?

public static Boolean UpdateMessageState(int messageId, int stateId, string message)
{
    var repo = new MailItemRepository();
    try
    {
        var objTask = repo.GetMailByMailId(messageId);

        objTask.State = stateId;
        objTask.Result = message;
        repo.Save();

        return true;
    }
    catch (Exception ex)
    {
        logger.Info(ex.Message);
        logger.Info(ex.InnerException);
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

错误跟踪:

2012-07-02 15:26:38.1002|INFO|EF.Methods.MailMethods.UpdateMessageState|System.Data.SqlClient.SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
The statement has been terminated.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand …
Run Code Online (Sandbox Code Playgroud)

c# linq-to-entities entity-framework timeout exception-handling

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