小编for*_*rir的帖子

ASP.Net MVC2 DropDownListFor

我试图在一个项目中学习MVC2,C#和Linq到实体(是的,我很生气),我遇到了一些DropDownListFor问题,并将SelectList传递给它.

这是我的控制器中的代码:

public ActionResult Create()
{
    var Methods = te.Methods.Select(a => a);

    List<SelectListItem> MethodList = new List<SelectListItem>();

    foreach (Method me in Methods)
    { 
        SelectListItem sli=new SelectListItem();
        sli.Text = me.Description;
        sli.Value = me.method_id.ToString();
        MethodList.Add(sli);
    }

    ViewData["MethodList"] = MethodList.AsEnumerable();

    Talkback tb = new Talkback();
    return View(tb);
} 
Run Code Online (Sandbox Code Playgroud)

和我有麻烦试图让DropDownListForMethodListViewData.当我尝试:

<%:Html.DropDownListFor(model => model.method_id,new SelectList("MethodList","method_id","Description",Model.method_id)) %>
Run Code Online (Sandbox Code Playgroud)

它出错以及以下消息

DataBinding: 'System.Char' does not contain a property with the name 'method_id'.
Run Code Online (Sandbox Code Playgroud)

我知道为什么会这样,因为它是MethodList一个字符串,但我无法弄清楚如何让它采取SelectList.如果我按照正常情况执行以下操作DropDownList:

<%: Html.DropDownList("MethodList") %>
Run Code Online (Sandbox Code Playgroud)

对此非常满意. …

c# asp.net-mvc-2

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

如何使用MOQ框架为抽象基类创建Mock?

我想为MyClass编写单元测试,但它的基类是一个抽象类.

public class MyClass : AbstractBaseClass
{
}
Run Code Online (Sandbox Code Playgroud)

我想模拟AbstractBase类,这样当我创建我想要测试的MyClass实例时,我可以跳过其构造函数中的一些逻辑.无论如何我能做到吗?

//Unit Test
var test = new Mock<IInterface>();
var derivedclass = new DerivedClass(test.Object);

test.Setup(d=>d.MyMethod(It.IsAny<string>()).returns(2);
derivedclass.MyMethod("hello");


// Derived Class
class DerivedClass : AbstractClass{

     //constuctor
    public DerivedClass(IInterface interface){
        _interface = interface;
    }
    public MyMethod(string str){
        return 2;
    }
}

//Abstract Class
public abstract class AbstractClass
{

 // This method gets called when i create the  instance of the derived class in my unit   
  test..

   protected AbstractedClass() : this(new SomeOtherClass()){
       DoSomethingElse();    /// I want to …
Run Code Online (Sandbox Code Playgroud)

unit-testing moq

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

简单的Java文件传输程序问题

我正在尝试从服务器到客户端进行简单的文件传输.

它需要像这样:

客户端要求提供文件.

服务器将文件发送到客户端.

现在在代码中(下面)(这是我找到的唯一代码,很难找到)它只向我发送一个"好"的文本文件(甚至只能使它成为客户端中的一行).如果我尝试发送任何其他文件类型(如图像或rar文件),它会被损坏.

那么,有人可以帮我找一些可以发送和接收所有类型文件的工作代码(用Java),或者向我解释这段代码的问题是什么.

服务器端:

public class FileServer {   
    public static void main(String args[])throws IOException
    { 
        ServerSocket ss=null;
        try
        {  
            ss=new ServerSocket(8081);
        }
        catch(IOException e)
        { 
            System.out.println("couldn't listen");
            System.exit(0);
        }
        Socket cs=null;
        try
        { 
            cs=ss.accept();
            System.out.println("Connection established"+cs);
        }
        catch(Exception e)
        { 
            System.out.println("Accept failed");
            System.exit(1);
        } 
        PrintWriter put=new PrintWriter(cs.getOutputStream(),true);
        BufferedReader st=new BufferedReader(new InputStreamReader(cs.getInputStream()));
        String s=st.readLine();
        System.out.println("The requested file is : "+s);
        File f=new File(s);
        if(f.exists())
        { 
            BufferedReader d=new BufferedReader(new FileReader(s));
            String line;
            while((line=d.readLine())!=null)
            {
                put.write(line);
                put.flush();
            }
            d.close();
            System.out.println("File …
Run Code Online (Sandbox Code Playgroud)

java client-server file-transfer

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

在类定义之外定义静态const

我们应该static const在类定义之外定义一个成员,即使它是在类中初始化的吗?

#include<iostream>  
using namespace std;  
class abc  
{  
    static const int period=5;  
    int arr[period];  
  public:  
    void display()   
    {   
        cout<<period<<endl;  
    }  
};

const int abc::period;   

int main()   
{   
    abc a;  
    a.display();   
    return 0;  
}
Run Code Online (Sandbox Code Playgroud)

评论之后// const int abc::period;,两个版本的代码在gcc 4.3.4上运行良好.所以我想问为什么两个版本都可以使用,哪个版本符合标准?

c++ c++11

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

如何使用microsoft visual c ++编写代码来调用JNI

屏幕抓取

我该如何编写C代码microsoft visual c++ 2010 Express我无法做到.我正在编写一些C代码,但它编译时出错.

请建议一些方法来做到这一点?

我写了这段代码:

#include "jni.h"
#include "stdio.h"
#include "HelloWorld.h"

JNIEXPORT void JNICALL
Java_HelloWorld_print(JNIEnv *env, jobject obj) {
    printf("This is a JNI tester");
    return;
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

helloworld.cpp(1):致命错误C1083:无法打开包含文件:'jni.h'没有这样的文件或目录

c c++ java-native-interface visual-c++

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

NuGet项目>添加库包参考未出现

我安装了NuGet.

当我尝试转到Project> Add Library Package Reference时

"添加库包参考"不在项目菜单下.如果我再次尝试安装NuGet,它说它已经安装好了.我的应用程序是一个针对.net 4的MVC 3应用程序.

如何才能显示此选项?

asp.net-mvc visual-studio-2010 nuget

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

在使用asp.net登录5次失败后,如何锁定用户帐户30分钟?

我使用asp.net会员提供程序来管理用户.我要求在5次尝试失败后锁定用户帐户30分钟.我应该如何在服务器端使用asp.net成员资格提供程序?

此外,我希望"密码应在3个月后过期","最后10个使用过的密码应该被记住".有没有办法解决这些要求.

c# asp.net asp.net-mvc

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

Android中的进度对话框问题

我想ProgressDialog在我的Activity中创建一个简单的.我这样创建它:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.channellist);

    final Context c=this;

    t1=(TextView) findViewById(R.id.channellistStatus);

    listView=(ListView) findViewById(R.id.channellist);

    rc=RCManager.getInstance();

    chlistAdapter = new ChannelListAdapter(this,R.layout.channellist_row_lyt,clist);

    listView.setAdapter(chlistAdapter);

    t1.setText("No Channel List Found...");

    progDailog=ProgressDialog.show(this,"HI", "Loading");

    new Thread(new Runnable() {

        @Override
        public void run() {
            try 
            {
                Thread.sleep(3000);
            } 
            catch (InterruptedException e) 
            {
                e.printStackTrace();
            }   
            updateChannelList();
        }
    }).start();
Run Code Online (Sandbox Code Playgroud)

但它导致以下异常,即WindowManager BadToken异常.我不知道为什么会这样.请有人帮我解决这个问题吗?

05-23 16:56:44.573: ERROR/AndroidRuntime(2494): FATAL EXCEPTION: main
05-23 16:56:44.573: ERROR/AndroidRuntime(2494): java.lang.RuntimeException: Unable            to start activity           ComponentInfo{com.nds.fr.activities/com.nds.fr.activities.TabGroup2Activity}:  java.lang.RuntimeException: Unable to start activity   ComponentInfo{com.nds.fr.activities/com.nds.fr.activities.ChannelListing}:  android.view.WindowManager$BadTokenException: Unable to add …
Run Code Online (Sandbox Code Playgroud)

android

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

FindBugs - 冗余比较为null

我有以下代码的findbugs错误,

if( obj instanceof CustomerData )
{
    CustomerData customerData = (CustomerData)obj;

    if (customerData == null) 
    {
        errors.reject("Error", "Null data received");
    }
}
Run Code Online (Sandbox Code Playgroud)

错误说明:

obj的冗余nullcheck,已知为非null(包名和方法名称,我因安全违规而删除)

此方法包含对常量null的已知非空值的冗余检查.

请告诉我这里的错误是什么.

java code-analysis findbugs

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

访问'if'语句之外的变量

如何insuranceCostif声明之外提供?

if (this.comboBox5.Text == "Third Party Fire and Theft")
{
    double insuranceCost = 1;
}
Run Code Online (Sandbox Code Playgroud)

c#

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