标签: model-view-controller

将 OnClick 事件添加到 Html.RadioButton

我想要做的是在用户单击单选按钮时调用 JavaScript 例程。发生这种情况时,我有一些字段可以启用/禁用。然而,当我进入

 <%=Html.RadioButton("obp17", "57", ViewData.Eval("obpValue17").ToString().Equals("57"), new {@onclick = "Yes()"})%>
Run Code Online (Sandbox Code Playgroud)

尝试添加 onlick 事件时,出现“键入或带有”预期错误。这应该很容易,但我发现的样本似乎都不起作用。前导“@”在我发现的所有示例中都很常见,但似乎缺少其他东西。

是的,我知道检查“true”的方法有点矫枉过正,但它是用特殊用途的代码生成器创建的,因此没有任何额外的工作。

有什么想法吗?

model-view-controller asp.net-mvc

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

什么是业务逻辑?

可以使用术语业务逻辑来描述:

控制最终用户可以使用哪些数据的帐户角色(管理员、最终用户、未注册用户、主持人)?

如果没有,有人可以提供一个术语来描述上述情况,并准确地纠正我的业务逻辑意味着什么?它与业务规则有何不同?例子?您会将业务逻辑层放在 Rails/RoR 中的控制器中吗?

ruby model-view-controller business-logic ruby-on-rails business-rules

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

MVC - 以下方法或属性之间的调用不明确

我不明白为什么我会收到这个错误。我的项目中只有一个带有一种方法的类,如下所示:

public static class Extensions
{
    public static string Chop(this string s, int length)
    {
        ...
        return "";
    }
}
Run Code Online (Sandbox Code Playgroud)

我在我的视图中这样调用它: @item.PostContent.Chop(20)
它给了我一个编译器错误:

The call is ambiguous between the following methods or properties: 'Extensions.Chop(string, int)' and 'Extensions.Chop(string, int)'
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏。谢谢你。

model-view-controller asp.net-mvc-views

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

如何为某些视图控制器锁定iPhone的方向 - Swift?

我有2个视图控制器,VC1和VC2.

VC1目前以模态方式呈现VC2.

VC1唯一的方向应该是纵向,但VC2可以具有所有方向.

问题是当我在VC2中并且我旋转到横向模式然后解雇时,VC1也处于横向模式!那应该永远不会发生!

注意:没有导航控制器或UITabbarcontroller

我正在添加我的代码.

Appdelagate:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    if let rootViewController = self.topViewControllerWithRootViewController(rootViewController: window?.rootViewController) {
        if (rootViewController.responds(to: Selector(("canRotate")))) {
            // Unlock landscape view orientations for this view controller
            return .allButUpsideDown
        }
    }

    // Only allow portrait (standard behaviour)
    return .portrait;
}

private func topViewControllerWithRootViewController(rootViewController: UIViewController!) -> UIViewController? {
    if (rootViewController == nil) { return nil }
    if (rootViewController.isKind(of: (UITabBarController).self)) {
        return topViewControllerWithRootViewController(rootViewController: (rootViewController as! UITabBarController).selectedViewController)
    } else if (rootViewController.isKind(of:(UINavigationController).self)) …
Run Code Online (Sandbox Code Playgroud)

iphone model-view-controller screen-orientation ios swift

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

无法将类型'System.Net.Mail.MailAddress'隐式转换为'SendGrid.Helpers.Mail.EmailAddress'

我正在尝试发送电子邮件并收到此错误

无法将类型'System.Net.Mail.MailAddress'隐式转换为'SendGrid.Helpers.Mail.EmailAddress'

    var myMessage = new SendGridMessage();
        myMessage.AddTo(message.Destination);
        myMessage.From = new MailAddress("you@somewhere.com", "My name");//here the error Happens
        myMessage.Subject = message.Subject;
        myMessage.PlainTextContent = message.Body;
        myMessage.HtmlContent= message.Body;
Run Code Online (Sandbox Code Playgroud)

c# email model-view-controller

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

对象C#的JSON(将复杂的API响应映射到C#对象)

我能够处理简单的JSON序列化和反序列化,但是这个API响应看起来并不复杂,我正在寻求一个关于解决这个问题的理想方法的建议.

我正在尝试为MVC应用程序调用API.目标是将API数据映射到模型.API端点是 https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=MyAPIKey

这里的麻烦是:

  1. JSON数据键中包含空格.
  2. 当我尝试在Visual Studio中执行特殊粘贴时,它分别为每个日期条目提供了一个很长的类列表,因为此API调用返回一组单独的日期信息.

为了解决第1点中解释的问题,我[JsonProperty("1. Information")]在课堂上使用过.在我的代码..

        public async Task TSI()
        {
            HttpClient client = new HttpClient();
            //Uri uri = new Uri("http://date.jsontest.com/");
            Uri uri = new Uri("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=demo");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = await client.GetAsync(uri);
            if (response.IsSuccessStatusCode)
            {
                dynamic result = await response.Content.ReadAsAsync<object>();

                IEnumerable<dynamic> dObj = JsonConvert.DeserializeObject<dynamic>(result.ToString());

                IEnumerable<dynamic> t1 = dObj.FirstOrDefault();
                IEnumerable<dynamic> t2 = dObj.LastOrDefault();
                dynamic MetaData = t1.FirstOrDefault();

                Rootobject ro = new Rootobject();
                ro.MetaData = MetaData;

            }
Run Code Online (Sandbox Code Playgroud)

PS:我是一个相对较新的API调用和处理它们.

我能打电话给

date.jsontest.com

并将API数据映射到模型(我使用粘贴特殊创建)

//API response
    {
        "time": …
Run Code Online (Sandbox Code Playgroud)

c# api model-view-controller json.net

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

从angularJs调用java控制器

这是我的情况,我在Netbeans 8.2中有一个项目,在html中,这里调用angularjs,但是当需要从angular调用java控制器时我们在chrome调试中收到"not found",在工厂用$ http发送"url",但我不能调用java控制器.

- 这是代码html

<div data-ng-app="myApp">
<div data-ng-controller="MyController">
<button data-ng-click="getDataFromServer()">Test Angularjs</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)

- 这是angularjs中的代码(这是一个File.js)

var app = angular
        .module('myApp', ['ngRoute', 'ngResource'])

        .controller('MyController', function ($scope, $service, $http, $resource) {          
            $scope.getDataFromServer = function () {

                $service.JS_STST_GetData();
            }

        })// end controller    
.factory(
        '$service',
        function ($http) {
            return {
                JS_STST_GetData: function (){
                    $http({
                        method: 'POST',
                        url: 'TestMaping',
                        headers: {
                            'Content-Type': 'application/json'
                        }
                    }).then(_success, _error);
                },
Run Code Online (Sandbox Code Playgroud)

- 这是Java控制器代码

@Controller
public class VerController {

    @RequestMapping(value="/TestMaping", method = RequestMethod.POST)
    public String TEST(Model model){
        return …
Run Code Online (Sandbox Code Playgroud)

java model-view-controller controller angularjs

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

在osx上启动dotnet核心应用程序的问题

由于一些奇怪的原因,我无法在osx上启动任何mvc或webapp项目.

应用程序使用此输出按预期启动.

Using launch settings from /Users/erik/Development/DotNetProjects/Funka/Funka/Properties/launchSettings.json...
Hosting environment: Development
Content root path: /Users/erik/Development/DotNetProjects/Funka/Funka
Now listening on: https://localhost:5001
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
Run Code Online (Sandbox Code Playgroud)

当第一个请求传递给上面的任何地址时,我得到了这个堆栈跟踪,我无法弄清楚为什么因为项目刚刚创建,所以不对代码进行任何修改.

错误:

fail: Microsoft.AspNetCore.Server.Kestrel[0]
      Uncaught exception from the OnConnectionAsync method of an IConnectionAdapter.
System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception. ---> Interop+AppleCrypto+SslException: Internal error
   --- End of inner exception stack trace ---
   at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at …
Run Code Online (Sandbox Code Playgroud)

.net model-view-controller core kestrel

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

将jquery对象转换为DOM并使用appendChild函数

我必须移动输入元素.在变量测试中我得到了很好的元素:

var test = $('#AttributeValue_StringRepresentation').parent('td');
Run Code Online (Sandbox Code Playgroud)

但我不知道如何使用appendChild,我试过:

test.appenChild(document.getElementById(AttributeValueId));
test[0].appenChild(document.getElementById(AttributeValueId));
Run Code Online (Sandbox Code Playgroud)

我也试过了

document.getElementsByName(test)[0].appenChild(document.getElementById(AttributeValueId));
Run Code Online (Sandbox Code Playgroud)

一般来说,我的想法已经完成,我找到了一些解决方案但它现在正在运行 我没有测试变量的ID或任何东西而且我被卡住了

javascript model-view-controller jquery kendo-ui

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

PHP-使用MVC构建Slim3 Web应用程序并了解模型的作用

我正在尝试使用Slim3框架以及Twig模板系统在php中创建一个身份验证系统,对于数据库,我正在使用MySQL和PDO。我也在尝试使用模型视图控制器设计模式来实现它。但是我很难理解如何为Web应用程序使用MVC结构。我在网上查看了过多的解释,似乎没有明确的答案。很多人说要使用PHP框架,例如Laravel,Symfony或CodeIgniter,因为他们显然采用了类似MVC的结构。但是,我宁愿保持简单,并手动编写代码,而不是使用框架。

我目前对MVC有两种解释。此图中描绘了第一个:

在此处输入图片说明

我看到的另一种解释是:(摘自该YouTube视频)

在此处输入图片说明

我已经做了研究。问题和答案,如这和这个是有帮助的。但是我仍然不确定如何构造自己的应用程序,特别是识别和理解MVC的模型方面。现在,我将说明身份验证应用程序的注册过程。这样您就知道我的代码是如何工作的。

首先,我有一个SQLQueries类,该类将一系列SQL语句简单地放入函数中。然后,我有一个SQLWrapper类,该类具有的功能可以例如在数据库中存储新用户的详细信息。此类还从SQLQueries类调用函数。我也有一个ValidateSanitize类,该类具有清理用户输入以及检查用户输入在表单中是否有效的功能。我认为这三个类是MVC模型方面的一部分,但我不确定。我看到了许多其他的使用“用户模型类”的教程,但我的应用程序中找不到它们。

我的视图只是显示HTML的Twig模板,例如主页,注册,登录等。然后我有了控制器。我打算让多个控制器执行不同的操作。目前,我只实现了AuthController,该控制器负责注册和登录用户。

因此,AuthController要做的第一件事是在名为getRegisterForm的函数中显示注册表。用户提交表单后,postRegisterForm函数将获取该用户输入并将其分配给有污染的变量。

public function postRegisterForm($request, $response)  
{
   $arr_tainted_params = $request->getParsedBody(); 

   $tainted_email = $arr_tainted_params['email'];  it a variable
   $tainted_username = $arr_tainted_params['username'];
   $tainted_password = $arr_tainted_params['password'];
   $tainted_password_confirm = $arr_tainted_params['password_confirm'];
Run Code Online (Sandbox Code Playgroud)

接下来,实例化所有前面的三个类以及数据库详细信息,以便可以在AuthController中使用它们的功能:

$sanitizer_validator = $this->container->ValidateSanitize;
$sql_wrapper = $this->container->SQLWrapper;
$sql_queries = $this->container->SQLQueries;
$db_handle = $this->container->get('dbase');
Run Code Online (Sandbox Code Playgroud)

然后,使用sanitize_input函数清除受污染的用户详细信息。然后,将清理后的用户详细信息输入到validate函数中,以确保它们不会触发任何验证冲突。密码也在此处散列:

$cleaned_email = $sanitizer_validator->sanitize_input($tainted_email, FILTER_SANITIZE_EMAIL); 
$cleaned_username = $sanitizer_validator->sanitize_input($tainted_username, FILTER_SANITIZE_STRING);
$cleaned_password = $sanitizer_validator->sanitize_input($tainted_password, FILTER_SANITIZE_STRING);
$cleaned_password_confirm = $sanitizer_validator->sanitize_input($tainted_password_confirm, FILTER_SANITIZE_STRING);

$hashed_cleaned_password = password_hash($cleaned_password, PASSWORD_DEFAULT); 

$sanitizer_validator->check_email_exists($cleaned_email);
$sanitizer_validator->validate_email($cleaned_email);
$sanitizer_validator->validate_username($cleaned_username);
$sanitizer_validator->validate_password($cleaned_password);
$sanitizer_validator?validate_password_confirm($cleaned_password_confirm);
Run Code Online (Sandbox Code Playgroud)

最后,有一个if语句,检查所有验证错误消息是否为空。如果是的话,我们将为SQLWrapper类提供数据库详细信息以及SQLQueries类对象。然后,通过调用SQLWrapper类store-details函数将用户详细信息插入数据库。最后,我们将用户定向到登录页面,以便用户可以登录其新注册的帐户。

if ($sanitizer_validator->get_validate_messages('email_error') == ' …
Run Code Online (Sandbox Code Playgroud)

php model-view-controller design-patterns model slim-3

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