asp.net mvc测试我的service层的方法是不是正确

huangkangyi163 2010-06-09 10:44:07
我用asp.net mvc开发 我新建一个mvc项目 在Models文件夹里新建一个类test.cs 在里面写了一方法
public class test
{
public int A { get; set; }
public int B { get; set; }
public int Add(test c)
{
int d=c.A+c.B;
return d;
}
}
然后在Controllers文件夹中新建了一个UsertController.cs 里面写了一个方法用来接收我的Add()方法
public ActionResult ddd()
{
sd.A = 2;
sd.B = 3;
return View(sd.Add(sd));
}
我在选择Add View... 出来选则我自己的测试类 选择Details........
添加了一个页面在Views自己新建Usert文件夹 选择Add View...添加页面ddd.aspx

我运行页面出现了一个
The model item passed into the dictionary is of type 'System.Int32', but this dictionary requires a model item of type 'MvcApplication3.Models.test'. 错误
我的测试就此完成不了 不知道我的方法是否写的正不正确
高手能不能不能指点一下
有什么方法可以测试我的方法是不是正确的 有没有哪种方法跟好测试 能教我测试我的
能发一个简单的测试到得邮箱吗 h516952364@qq.com
...全文
79 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
huangkangyi163 2010-06-10
  • 打赏
  • 举报
回复
我的view都是自己生成的的啊 应该没有错误吧
fanshuyi 2010-06-10
  • 打赏
  • 举报
回复
给你个例子:http://www.baoshuiqu.com/contents/12/4657.html
皇城龙三 2010-06-09
  • 打赏
  • 举报
回复
应该是你的某个字段为null或者字段名不对,导致MVC的View识别不了
1 Getting Started with ASP.NET MVC 1.1 How ASP.NET MVC Works 1.2 Installing MVC 1.3 MVC in Five Minutes: Building Quote-O-Matic 2 Test-Driven Development 2.1 TDD Explained 2.2 Test-Driving “Hello World” II Building an Application 3 Getting Organized with MVC 3.1 Time Management with GetOrganized 3.2 Reading Data 3.3 Creating a To-Do 3.4 Deleting: Creating an Action Without a View 3.5 Updating: Marking a To-Do as Complete 4 Working with Controllers 71 4.1 Creating Topics 4.2 Using the FormCollection and TempData Objects 4.3 Adding a Little Color with jQuery 4.4 Controllers Talking to Controllers 5 Managing State and Files with Controllers 5.1 Enabling Filters and Results with Controllers 5.2 Logging In 5.3 Testing Routes in MVC 5.4 Storing Information in Memory 5.5 Manipulating Files 6 Enhancing Views with HTML Helpers and Master Pages 6.1 Making Our Site Presentable with HTML Helpers 6.2 Building a Custom HTML Helper 6.3 Simplifying Page Layouts with Master Pages 6.4 Adding Validations Using ModelStateDictionary 6.5 Replacing Web Controls with Advanced HTML Helpers 7 Composing Views with Ajax and Partials 151 7.1 Working with Ajax 7.2 Finding It in a Snap with Autocomplete 7.3 Using Partials to Reduce Duplication III Integrating with Other Frameworks 8 Persisting Your Models 8.1 MVC’s Next Top Model: NHibernate 8.2 Using the Repository Pattern 8.3 Mapping with Fluent NHibernate 8.4 Creating and Reading Records 8.5 Editing Models 8.6 Deleting Records 8.7 Additional ORM Data Relationships 9 Integrating Repositories with Controllers 9.1 Fixing the NHibernate Session Inside MVC 9.2 Using Inversion of Control with the IControllerFactory 9.3 Injecting Repositories into Controllers 9.4 Creating a Custom Action Filter 9.5 Linking NHibernate and MVC Validations 9.6 Preventing Performance Problems with Profiling 10 Building RESTful Web Services 210 10.1 Use SOAP or Take a REST Instead? 10.2 Creating a Web Service 10.3 Publishing to Blogger IV Security and Deployment 11 Security, Error Handling, and Logging 11.1 Applying Additional Security 11.2 Using an Action Filter to Handle Errors 11.3 Using Logging to See What Went Wrong 11.4 Checking for a Pulse with ASP.NET Health Monitoring 12 Build and Deployment 12.1 Automating Builds 12.2 Using MSBuild to Automate the Build 12.3 Deploying to Production

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧