模型验证在本地但不在服务器上正常工作

时间:2016-03-25 05:43:29

标签: asp.net-mvc asp.net-mvc-4

我已经实现了客户端模型验证,它是本地的工作文件, 但是在服务器上,即使我的文本框为空,它也会显示错误,但会触及控制器各自的方法。

1 个答案:

答案 0 :(得分:1)

服务器对于向客户端发送错误更具限制性。尝试在#include <iostream> #include <memory> #include <string> template<typename T> class LinkedList { public: struct Node; using NodeType = std::shared_ptr<Node>; struct Node { NodeType next; T value; }; class forward_iterator { NodeType cur_node; public: forward_iterator() {} forward_iterator(NodeType cur_node) : cur_node(cur_node) {} T& operator * () { return cur_node->value; } forward_iterator& operator ++ () { cur_node = cur_node->next; return *this; } bool operator == (const forward_iterator& it) const { return cur_node == it.cur_node; } bool operator != (const forward_iterator& it) const { return !operator == (it); } }; void push_back(const T& t) { NodeType node = std::make_shared<Node>(); if(tail) { tail->next = node; tail = node; } else { head = tail = node; } node->value = t; } forward_iterator begin() { return forward_iterator(head); } forward_iterator end() { return forward_iterator(); } protected: NodeType head, tail; }; inline std::string upper_case(const std::string& s) { std::string r; for(auto c : s) { if(c >= 'a' && c <= 'z') c = c - 'a' + 'A'; r.push_back(c); } return r; } template <typename Func, typename S> inline S Map(Func func, S seq) { S result; for(const auto& elem : seq) { result.push_back(func(elem)); } return result; } int main() { // add strings to a LinkedList of strings named "original" static const char* my_data[] = { "Hello", "1234", "John Cena", "xd" }; LinkedList<std::string> original; for(auto cstr : my_data) { original.push_back(cstr); } // dump "original" to cout std::cout << "-- original --\n"; for(const auto& s : original) { std::cout << s << '\n'; } std::cout << '\n'; // Run the generic Map function with "original" as input // A lambda will be called for each element and // its returned value added to the result, named "mapped". // A functor object may be used in place of the lambda auto mapped = Map( [](const std::string& s) { return upper_case(s); }, original); // dump "mapped" to cout std::cout << "-- mapped --\n"; for(const auto& s : mapped) { std::cout << s << '\n'; } std::cout << '\n'; } 上设置IncludeErrorDetails标记,以验证这是潜在问题。

一般情况下,虽然打开此标志并不是最好的主意,但您希望以不同方式将错误序列化。

了解更多信息:click here