小编Tho*_*mas的帖子

如何以相同的形式处理多个提交按钮

我是mvc的新手.我知道这种方式我可以处理相同形式的多个提交按钮.

<%
 using (Html.BeginForm("LoginRegistration", new { action = "LoginRegistration", controller = "Register"}, FormMethod.Post, new { @class = "form", id = "formId" }))
    {
     %>
        //your html code here
        <input type="submit" name="submitButton" value="Login"/>
        <input type="submit" name="submitButton" value="Register"/>
<% }%>

[HttpPost]
        public ActionResult LoginRegistration(string submitButton)
        {
            switch (submitButton)
            {
                case "Login":
                    return RedirectToAction("Login");
                case "Register":
                    return RedirectToAction("Register");
                default:
                    return null;
            }
        }
Run Code Online (Sandbox Code Playgroud)

在我的情况下,我必须为所有提交按钮提供按钮名称submitButton但我想给所有提交按钮提供不同的名称.可能吗?

我想知道有没有其他方法来处理这种情况.所以请用示例代码讨论所有其他方式来处理这种情况.谢谢

UPDATE

我看到另一个人以下面的方式处理同样的问题.代码给出但我不明白他的伎俩.他为一个提交按钮添加了一个隐藏字段...为什么?他将按钮值属性设置为true,并将相应的隐藏字段的value属性设置为false ...为什么我无法理解这个技巧.

另一个问题是何时调用action方法然后将如何传递bool值以及哪个控件的bool值将通过....请仔细阅读此更新的代码并指导我此代码如何工作.谢谢

<%
 using (Html.BeginForm("LoginRegistration", new { action = "LoginRegistration", controller = "Register"}, FormMethod.Post, new { …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc

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

如何推动自定义控制器工厂ASP.Net MVC

我是mvc地区的新手.所以我还在学习,并试图在MVC中学习很多先进的领域.所以我正在阅读关于自定义控制器工厂ASP.Net MVC的帖子.

一个人解释得那么少,所以我只是不明白如何实施.这里是post url 在asp.net mvc中是否可以制作通用控制器?

他说

/Product/Index想要触发MyController<Product>.Index()

这可以通过编写自己的IControllerFactory并实现如下CreateController方法来实现:

public IController CreateController(RequestContext requestContext, string controllerName)
{
    Type controllerType = Type.GetType("MyController").MakeGenericType(Type.GetType(controllerName));
    return Activator.CreateInstance(controllerType) as IController;
}
Run Code Online (Sandbox Code Playgroud)

需要更多示例代码.只是不明白在哪里定义CreateController功能.我需要在基本控制器中编写此功能吗?

当请求到达时,/Product/Index或者/Customer/Index如何在基本控制器中调用索引方法?

所以在MVC高级领域寻找像我这样的新手的指导.谢谢

c# asp.net-mvc

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

如何异步调用wcf服务

如果wcf服务设计如下,那么请指导我如何从客户端调用Add()函数Asynchronously.谢谢

[ServiceContract]
public interface IAddTwoNumbers
{
    // If the asynchronous method pair
    // appears on the client channel, the client can call 
    // them asynchronously to prevent blocking.
    [OperationContract (AsyncPattern=true)]
    IAsyncResult BeginAdd(int a, int b, AsyncCallback cb, AsyncState s);

    [OperationContract]
    int EndAdd(IAsyncResult r);

    // This is a synchronous version of the BeginAdd/EndAdd pair.
    // It appears in the client channel code by default. 
    [OperationContract]
    int Add(int a, int b);
   }
Run Code Online (Sandbox Code Playgroud)

.net c# wcf asynchronous

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

SSL 和证书如何在服务器和浏览器之间工作

我不太了解 SSL 和证书在服务器和浏览器之间如何工作。所以我从这个网站http://www.tldp.org/HOWTO/SSL-Certificates-HOWTO/x64.html上写了一些关于这个问题的文章,无论他们说的对我来说不是很清楚

他们说

1) A browser requests a secure page (usually https://).

2) The web server sends its public key with its certificate.

3) The browser checks that the certificate was issued by a trusted party 
   (usually a trusted root CA), that the certificate is still valid and that the 
   certificate is related to the site contacted.

4) The browser then uses the public key, to encrypt a random symmetric 
   encryption key and sends it to the …
Run Code Online (Sandbox Code Playgroud)

ssl certificate

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

单例设计模式优先用于获取数据库连接

我看到许多开发人员为数据库连接创建了Singleton类.我只是想知道当许多用户使用应用程序时它是好还是坏.如果不好请讨论上述模式可能发生的所有不良情况.

public class ConnSingleton
    {
        private static ConnSingleton dbInstance;
        private readonly SqlConnection conn = new SqlConnection(@"Data Source=127.0.0.1;database=soa;User id=sa1;Password=sa1;");       

        private ConnSingleton()
        {
        }

        public static ConnSingleton getDbInstance()
        {
            if (dbInstance == null)
            {
                dbInstance = new ConnSingleton();
            }
            return dbInstance;
        }

        public SqlConnection GetDBConnection()
        {
            try
            {
                conn.Open();
                Console.WriteLine("Connected");
            }
            catch (SqlException e)
            {
                Console.WriteLine("Not connected : "+e.ToString());
                Console.ReadLine();
            }
            finally
            {
                Console.WriteLine("End..");
               // Console.WriteLine("Not connected : " + e.ToString());
                Console.ReadLine();
            }
            Console.ReadLine();
            return con;
        }

    }

public static void Main(string[] …
Run Code Online (Sandbox Code Playgroud)

c# oop singleton

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

如何通过批处理文件创建MAP驱动器

我经常需要创建地图驱动器,我指定机器和用户凭证.现在我想知道我们可以写一个批处理文件,它将创建地图驱动器,我提供所有细节,如电脑和文件夹位置和用户凭据等.我有一个如下,但我认为这不是我需要的.请指导我.谢谢

net use \\<network-location>\<some-share>\ password /USER:username

@echo Create new L: drive mapping
@net use L: \\network path /persistent:yes
@echo Create new K: drive mapping
@net use K: \\network path /persistent:yes
:exit
Run Code Online (Sandbox Code Playgroud)

如果我这样做...那么它是否有效

net use y: \\192.168.7.15\$D\testfolder password /USER:username  /PERSISTENT:YES
Run Code Online (Sandbox Code Playgroud)

请指导.....语法还可以吗?

batch-file network-drive

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

如何使用 html、css 和 js 文件构建可在任何 Android 手机上运行的 APK 文件

我不知道如何开发在 Android 手机上运行的移动应用程序。只是浏览良好,发现一个网址,我看到他们的应用程序可以将我的 html 文件转换为 apk 文件。这是HTML 到 APK 的url

我喜欢开发一个小型应用程序,它将直接打开相机,当用户拍摄任何照片时,图片将显示在我的 html 图像控件中。

我有另一个网址http://www.ripperdesignandmultimedia.com/2012/09/06/jquery-mobile-use-phone-camera-using-cordova-2-0/

他们展示了如何做到这一点。他们说我需要与Cordova js

what is Cordova ?
Run Code Online (Sandbox Code Playgroud)

它是任何库或框架吗?

那么请告诉我,如果我按照上述网址开发代码,然后使用另一个应用程序将该 html 文件转换为 apk,然后告诉我我的 apk 是否可以工作?

指导我如何构建我的 apk,因此所有运行时环境都应该安装在 Android 手机中才能成功运行我的应用程序。i know .Net technology, html, jquery and javascript. what else i need to know.

谢谢

html javascript jquery android cordova

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

AngularJS自定义服务注入

我正在学习角度,这就是为什么有一段时间我不理解代码.我有一个角度定制服务的代码.首先看代码.

angular.module('yourModule').factory('alertService', function() {
    return {
        showError : function() {
            $.bigBox({
                title: title,
                content: content == null ? "An error occurred.<br /><br />If this error    persists, please contact support." : content,
                color: "#C46A69",
                //timeout: 6000,
                icon: "fa fa-warning shake animated",
                //number: "1",
                timeout: 3000
            });
        }
    };
});
Run Code Online (Sandbox Code Playgroud)

然后你可以将它注入任何控制器并使用它:

angular.module('yourModule').controller('yourController', function($scope, alertService) {
   someFunction().success(function (result) {
       // great!
   }).error(function (error) {
       // call standard error message function
       alertService.showError("Update Failed"); // use default error message
   });
});
Run Code Online (Sandbox Code Playgroud)

问题1

当注入内置服务然后我们使用$ sign这样的方式$ …

angularjs

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

对于xml自动输出,具有空间问题的字段名称

我的sql很简单

选择ID作为[员工ID],EmpName作为[员工姓名],Sal作为[薪资]来自Emp FOR XML AUTO,ELEMENTS,ROOT('customers')

当我执行这个SQL然后我得到xml格式的输出.xml输出是

<customers>
<Emp>
  <Employee_x0020_ID>1</Employee_x0020_ID>
  <Employee_x0020_Name>Tridip</Employee_x0020_Name>
  <Salary>2500</Salary>
</Emp>
<Emp>
  <Employee_x0020_ID>2</Employee_x0020_ID>
  <Employee_x0020_Name>Ari</Employee_x0020_Name>
  <Salary>4000</Salary>
</Emp>
<Emp>
  <Employee_x0020_ID>3</Employee_x0020_ID>
  <Employee_x0020_Name>Dibyendu</Employee_x0020_Name>
  <Salary>3500</Salary>
</Emp>
</customers>
Run Code Online (Sandbox Code Playgroud)

如果您看到xml字段名称,那么您可以理解由于空格而动态生成字段名称.<Employee_x0020_ID> 1 </ Employee_x0020_ID>这是动态生成的,但我希望它应该像<Employee ID> 1 </ Employee ID>一样生成.我希望空间应该保存在xml字段名称中.所以请告诉我该怎么做........谢谢

sql t-sql sql-server sql-server-2005 for-xml

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

在gridview上使用Listview

我对gridview非常熟悉.listview和gridview都用于生成包含数据的表格输出.所以请讨论一下应该使用listview而不是gridview的好处.谢谢.

asp.net

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