小编Sir*_*lly的帖子

TryUpdateModel,ASP .NET MVC 3的真实示例

我无法理解,如何使用TryUpdateModel并同时保存MVC架构.

如果我没有弄错的话,使用datacontexts必须在模型中.所以,这样的代码

var db=new TestEverybody();//it is class, which was generated by EntityFramework 
var currentTesting=db.Testing.(t => t.id == id).First();
Run Code Online (Sandbox Code Playgroud)

必须位于模型中,而不是控制器中,不是吗?

但TryUpdateModel用法的示例如下:

    public ActionResult Edit(Testing obj)//Testing collection
    {
        var db = new TestEverybody();
        var currentTesting=db.Testing.(t => t.id == obj.id).First();
        TryUpdateModel(currentTesting);
        db.SaveChanges();            
        return RedirectToAction("Index");
    }
Run Code Online (Sandbox Code Playgroud)

这种方式不会打破MVC架构吗?我们在控制器中使用数据库,而不是在特殊的Model类中.

那么,在真实项目中使用TryUpdateModel的最佳方法是什么?

asp.net-mvc controller model

29
推荐指数
2
解决办法
4万
查看次数

使用border-radius.htc为IE输入<input type ='text'/>的圆角

我想创建一个带圆角的输入字段.

HTML:

<div id="RightColumn">
<input type="text" class="inputForm" />
</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

.inputForm
{
    -moz-border-radius:10px; /* Firefox */
    -webkit-border-radius: 10px; /* Safari, Chrome */
    -khtml-border-radius: 10px; /* KHTML */
    border-radius: 10px; /* CSS3 */
    behavior:url("border-radius.htc");
}

#RightColumn
{
    background-color:White;
}
Run Code Online (Sandbox Code Playgroud)

但IE并没有显示任何输入字段的边框 - 更圆的边框和简单的边框.当我删除#RightColumn的CSS样式时,IE会显示带圆角的输入字段.但是我需要#RightColumn的背景知识.

我该如何创建它?

css internet-explorer rounded-corners css3 internet-explorer-8

27
推荐指数
3
解决办法
14万
查看次数

记录javascript错误

我想在beta测试期间记录项目中的所有JS错误.现在我用以下方式做到:

window.onerror = myErrHandler;

function myErrHandler(message, url, line)
{
    $.ajax({
        cache: false,
        type: "post",
        data: {error:message, url:url, line:line, brouser:navigator.userAgent},
        url: "/Home/LogJavaScript/",
        async: true
    });
    return true;
}
Run Code Online (Sandbox Code Playgroud)

但这种方式无法获得有关调用堆栈的任何信息.因此,有关jQuery或任何其他外部脚本中的错误的信息无济于事.

有没有办法改善这种日志记录?

javascript error-handling jquery logging stack-trace

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

对于<a>,javascript:void(0)或onclick ="return false" - 哪个更好?

有一个基于javascript的界面 - 所以我不需要支持没有JavaScript的工作.

我有一个

<a>Something</a>
Run Code Online (Sandbox Code Playgroud)

带有JS代码的元素,它绑定了click事件 - 因此,我不想在用户点击后重新加载页面.

哪种方式更好?

1. <a href="javascript:void(0)">Something</a>
2. <a href="#" onclick="return false;">Something</a>
Run Code Online (Sandbox Code Playgroud)

每种方法有哪些优缺点?

javascript

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

PHP Comet.怎么做得更好?

我有一个简单的彗星聊天.JavaScript使用长轮询发送ajax请求.当服务器在数据库中查找新消息时,它会回答并提供JSON.接下来,JavaScript再次发送请求.

使用Javascript:

function cometConnect(){
$.ajax({
      cache:false,
      type:"get",
      data:'ts='+ts,
      url: urlBack,
      async: true,
      success: function (arr1) {
      //work with JSON
      //.....
      },
      complete:function(){
        cometConnect(true);
        nerr=false;
      },
      dataType: "text"
    }); 
}
Run Code Online (Sandbox Code Playgroud)

PHP

$flag=true;
$lastmodif = isset($_GET['ts']) ? $_GET['ts'] : 0;
while($flag){
  $q=mysql_query("SELECT text, posterId,modified, fromUserId,toUserId, login FROM commonMessage WHERE modified>$lastmodif");

      while($r=mysql_fetch_row($q)){
        $flag=false;
        //Prepare JSON... variable $resp
            //.........
      }

  usleep(5000); 
}
echo $resp;
Run Code Online (Sandbox Code Playgroud)

问题是:这个"while($ flag)"可以执行很长时间(如果没有人发布消息).因此,Apache可以抛出exeptions(最长执行时间,有时502 Bad Gateway或Gateway Timeout).

怎么解决?

使用.htaccess和"php_value max_execution_time 0"?

或者简单地从JavaScript发送新请求,当服务器返回错误时(它会使消息更慢)?

可能是,还有其他一些方法吗?

javascript php jquery chat comet

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

使用Entity Framework按时间戳列选择新记录

RowId我的SQL Server数据库中有一个带有timestamp column()的表.

我想根据此时间戳查询新行.SQL查询如下

SELECT *
 FROM [MyTable]
 where RowId>=0x0000000000A99B06
Run Code Online (Sandbox Code Playgroud)

0x0000000000A99B06 是上一个查询的最大时间戳值.

如何使用Entity Framework数据库优先进行此类查询?RowId映射到byte[]属性,我不知道如何比较LINQ查询中的字节数组.

.net sql sql-server timestamp entity-framework

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

ASP .NET MVC 3.会话过期太快了

我有一个页面(View),它在某些时间间隔内发送AJAX查询.用户可以很长时间使用此页面.但会议在大约40-60分钟后到期.所以AJAX请求不会返回有用的信息.

我的Web.config

<system.web>
  <sessionState
      timeout="259200"
      cookieName="SunTest.SessionId"
      regenerateExpiredSessionId="true"
      sqlCommandTimeout="200"
      stateNetworkTimeout="200">
  </sessionState>
<roleManager enabled="true" defaultProvider="SqlProvider" cacheRolesInCookie="true" cookieName=".ASPROLES" cookieTimeout="259200" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All">
  <providers>
    <add name="SqlProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="SqlServices" applicationName="/" />
  </providers>
</roleManager>
<authentication mode="Forms">
  <forms loginUrl="~" timeout="259200" protection="All" />
</authentication>   
Run Code Online (Sandbox Code Playgroud)

我已经改变了我的web.config

<appSettings>
    <add key="enableSimpleMembership" value="false" />
    <add key="autoFormsAuthentication" value="false" />
</appSettings>
<system.web>
  <sessionState 
      mode="SQLServer"
      allowCustomSqlDatabase="true"
      sqlConnectionString="Data Source=servername;Initial Catalog=dbname;User ID=username;Password=password"
      timeout="259200"
      cookieName="SunTest.SessionId"
      regenerateExpiredSessionId="true"
      sqlCommandTimeout="200"
      stateNetworkTimeout="200">
  </sessionState>
<roleManager createPersistentCookie="true" enabled="true" defaultProvider="SqlProvider" cacheRolesInCookie="true" cookieName=".ASPROLES" cookieTimeout="259200" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All">
  <providers>
    <add name="SqlProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="SqlServices" applicationName="/" /> …
Run Code Online (Sandbox Code Playgroud)

asp.net web-config session-cookies asp.net-mvc-3

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

IIS 7 上 net.tcp WCF 服务(mex 端点)的“找不到兼容的 TransportManager”错误

我使用以下配置创建了服务

<system.serviceModel>

<bindings>
  <netTcpBinding>

    <binding name="CommonUserNameBinding" maxConnections="1000" portSharingEnabled="True">
      <security mode="None">
      </security>
    </binding>

  </netTcpBinding>

</bindings>


<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

<services>
  <service name="MyNameSpace.SimplePluginService" behaviorConfiguration="CommonBehavior">

    <endpoint address="UserName"
              binding="netTcpBinding" 
              bindingConfiguration="CommonUserNameBinding" 
              name="MyNameSpace.Contracts.ISimplePluginServiceUserName" 
              contract="MyNameSpace.Contracts.ISimplePluginService">
      <identity>
        <dns value="WCfServer" />
      </identity>
    </endpoint>

    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"  />

    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:5812/Service/SimplePluginService.svc"/>
      </baseAddresses>
    </host>

  </service>
</services>


<behaviors>

  <serviceBehaviors>
    <behavior name="CommonBehavior">
      <serviceMetadata httpGetEnabled="True" policyVersion="Policy15" />
      <serviceDebug includeExceptionDetailInFaults="True"/>
        <serviceCredentials>

        <userNameAuthentication 
            userNamePasswordValidationMode="Custom"
            customUserNamePasswordValidatorType="Megatec.MasterTourService.CustomUserNameValidator, Megatec.MasterTourService"/>

        <serviceCertificate
            findValue="WCFServer"
            storeLocation="LocalMachine"
            storeName="My"
            x509FindType="FindBySubjectName"/>

        <clientCertificate>
          <authentication certificateValidationMode="PeerTrust" />
        </clientCertificate>

      </serviceCredentials>  
    </behavior>
  </serviceBehaviors>

</behaviors>

</system.serviceModel>

</configuration>
Run Code Online (Sandbox Code Playgroud)

我在本地 IIS 7.5 …

.net wcf net.tcp

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

用于Adobe Air应用程序的openFileDialog

我有一个桌面Adobe Air应用程序.我想将openFileDialog添加到我的应用程序,以询问用户他的项目的路径.不幸的是,我无法使用FileReference - 它只返回文件名,而不是路径.

    private function selectHandler(event:Event):void {
       var file:FileReference = FileReference(event.target);
       trace("selectHandler: name=" + file.name); //only name!
    }
Run Code Online (Sandbox Code Playgroud)

有没有办法在这样的应用程序中应用openFileDialog并获取用户选择的文件路径?

air openfiledialog actionscript-3 filepath

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