w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
TryUpdateModel - why does it update two objects?
Your update function is getting old values may be the reason that you are not using Page.IsPostBack Property in Page_Load like protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { // Your code.. } }

Categories : Asp Net

How do I update database without TryUpdateModel()
Based on https://github.com/NancyFx/Nancy/wiki/Model-binding, I would expect the following to work: // get a fresh copy of the user model for the purposes of getting the id (there may be a simpler way to do this) var rawUser = this.Bind<User>(); // read the user from the db var user = db.Users.Single(u => u.Id == rawUser.Id); // bind again, but using the db user as the target this.BindTo(user); // commit (I think EF may be smart enough not to do anything if BindTo() didn't actually change anything) db.SaveChanges();

Categories : C#

Use TryUpdateModel to bind partially supplied values
The view model is just for information coming from the client. So you have to remove the Name property and get it from somewhere else. If this is a view model also used by the administrator for example (who is able to enter/change the name) then the best would be a derived view model like this: public class Client { public string Email { get; set; } public int Id { get; set; } } public class ClientWithName : Client { [Required] public string Name { get; set; } }

Categories : Asp Net Mvc

Using TryUpdateModel to save an object on Edit Post with FormCollection
If there are fields on your model that aren't in the form and you don't want users to change then you can use an exclude list. The choice to use an include or exclude list will depend which is largest. An include list is more secure as if you forget to include something it can't be changed. Not using an include, or exclude list will leave you vulnerable to model stuffing where users can post extra values to change details they shouldn't be able to. public ActionResult Edit(int id, FormCollection form) { var jobToUpdate = db.Jobs .Include(x => x.JobNotes) .Where(x => x.JobID == id) .SingleOrDefault(); if (TryUpdateModel(jobToUpdate, String.Empty, null, new [] {"SecretField"}, form)) { db.SaveChanges(); return RedirectT

Categories : Asp Net Mvc

Rails string helper to turn "SimpleProduct" into "Simple Product" or even "simple product"
Running directly "SimpleProduct".titleize should do the work Reference: http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-titleize

Categories : Ruby On Rails

Bind a simple Map in a JAX-RS resource with Jackson
Assuming you don't want to write your own MessageBodyReader to tell the framework how to convert json to a generic Map, you could still accept a String and use Jackson to read it as in: @POST public Response create(String json) { Map<String,Object> map = new ObjectMapper().readValue(json, Map.class); //business logic... return Response.created(UriBuilder.fromPath("{id}").build(id)).build(); }

Categories : Json

Simple MD5 hash of a String
PhantomJs does not natively support MD5 but you can easily inject external script code using phantom.injectJs. You have just a find an implementation in javascript. MD5 is quite popular and not too difficult to implent. So there are many implementations such as crypto-js or wbond/md5-js. A very basic script using CryptoJS could be var system = require('system'); if (system.args.length != 2) { console.log("Usage: phantomjs md5_test.js input"); } else { if(phantom.injectJs('md5.js')) { console.log(CryptoJS.MD5(system.args[1])); phantom.exit(); } }

Categories : Javascript

Mapping a simple string with RestKit
When you use postObject, RestKit will try to apply the response data to the source object (your LoginRequest). So you need to add somewhere for that data to be stored and a (response) mapping and descriptor to process it. Also, if the string returned to you is: "47c4e389-be2b-466b-b015-c8d5682c4f0a" That isn't JSON and you'll have issues trying to process it as such.

Categories : IOS

Creating a simple String Struct
You need to allocate memory for the structure but also for text string. scanf("%s",str->text); str->text is an uninitialized pointer.

Categories : C

how to encode/decode a simple string
You probably need to elaborate on how you are going to use it and why, as you have just opened Pandora's box :) An encoding is reversible and should only be used to make data fit into something else (like base 64 binary data when you can only use text), a hash (like sha224) is not supposed to be reversible. If you want to verify a user entering a password, you hash it (with like sha224) and store the hash, then when the user enters password again, you hash their entry and compare. This is the simplified version, you also need to add "salt" to avoid a simple "dictionary attack". I won't elaborate as that wasn't the question you asked. To quickly answer your question you want an encryption library, like the cipher AES-128, which has a secret key and with the key you can recover the orig

Categories : Python

Simple Array to String Conversion
First, turn your array into an array, containing only the IDs with quotemarks around them (array_map), then join them together with a comma (join): echo join(', ', array_map( function($item) { return "'" . $item['ID'] . "'"; }, $your_array));

Categories : PHP

how to set value of simple form checkbox to String?
If you want to go with check_box then its possible: <%= f.input :status, :as => :check_boxes, collection: [['Completed', 'completed']] %> But you should not expect two values from a check_box. It will carry only one value. the reverse will be considered if the check box is not checked.

Categories : Ruby On Rails

greasemonkey simple string manipulation
var url = "www.something.com/item/4563/"; var matches = url.match(/item/(d+)/); var itemNumber = matches && parseInt(matches[1], 10); console.log(itemNumber); // => 4563

Categories : Misc

Simple string regular expression
if you go to http://gskinner.com/RegExr/ you can write this expression: ^(C0[0-9]*[0-9]{4})[^0-9] And in the content you put: C012345 - legal C047851 - legal C*1*54821 - not legal (does not starts with 'C0') C0412 - not legal (mismatch length) C0*a*4587 - not legal And you will see that it only matches what you want.

Categories : C#

Most simple way to get string containing time interval
As Joachim Pileborg noted higher in the comments there is no function for format a string from a duration object. But you can do it using duration_cast to convert time difference first to hours and then minutes and seconds. After that using C++11 to_string function you can concatenate them to get the resulting string. #include <chrono> #include <string> #include <sstream> #include <iomanip> int main() { using namespace std::chrono; steady_clock::time_point start = /* Some point in time */; steady_clock::time_point now = steady_clock::now(); int hhh = duration_cast<hours>(now - start).count(); int mm = duration_cast<minutes>(now - start).count() % 60; int ss = duration_cast<seconds>(now - start).count() % 60; std::o

Categories : C++

Passing simple string from one form to another
You need to pass the selecteddata to the form2 constructor. so modify the form 2 constructoo like this public form2(String SelectedData){ txtSelectedData.Text = SelectedData ; } and when creating an instance of form2, pass the value like this Form2 frm2 = new Form2(selectedOption.ToString());

Categories : C#

How to bind a simple string value to a text box?
You never set the value of your property. Simply defining set { _name2 = "abcdef"; } does not actually set the value of your property until you actually perform the set operation. You can change your code to look like this for it to work: public partial class EntitiesView : UserControl { private string _name2; public string Name2 { get { return _name2; } set { _name2 = value; } } public EntitiesView() { Name2 = "abcdef"; DataContext = this; InitializeComponent(); } } Also, as people have mentioned, if you intend to modify your property's value later on and want the UI to reflect it, you'll need to implement the INotifyPropertyChanged interface: public partial class EntitiesView : UserControl, INotifyPropertyChanged {

Categories : C#

Simple string replacement set of rules
Your approach of marking both beginning and end with % has one problem. What happens if the input string is %foo%%bar%? Do I get the value of foo and the value of bar? Or do I get the value of foo%bar? (Of course if % in variable names isn't allowed, this isn't a problem.) The simplest way I can think of to avoid this problem is to use one symbol for the beginning and another (e.g. #) for the end. That should avoid any ambiguity. If the user wants a # in text or a variable name, he escapes it like so: %#. This causes no problems, since empty variable names are not a thing (at least I hope not).

Categories : String

need another connection string to use simple membership provider
Prageeth, Assuming you mean the default implementation from the MVC 4 Internet Application template in Visual Sutdio 2012, then you can (and should) have a single connection string. In the template the only one initially is in InitializeSimpleMembershipAttribute, but you will need to add more (see the footnote) All you need to do is set the connection string name in your UsersContext class to that of your own. Do the same in the InitializeSimpleMembershipAttribute class, and also in any calls to WebSecurity.InitializeDatabaseConnection If you are using code-first (which, by the way, is the simplest approach when you first use SimpleMembership) you can also: move UserProfile from UsersContext into your own context, and delete UsersContext change the references to UsersContext in Accou

Categories : Asp Net Mvc

How to build a simple string from a multidimensional array?
something like this: var questionAnswerSet= { "question1" : [ { "answer1" : "value", "answer2" : "value", "answer3" : value} ], "question2" : [ { "answer1" : "value", "answer2" : "value", "answer3" : value} ], } and access like this: questionAnswerSet[0].answer2 // question one answer 2 questionAnswerSet[1].answer2 // question two answer 2

Categories : Javascript

Simple regex to get a twitter username from a string
Drop the {..} curly braces, they are not used with *: >>> re.findall(r"@w*", "@dasweo where you at?") ['@dasweo'] Only use {..} quantifiers with fixed numbers: w{3} matches exactly 3 letters, for example.

Categories : Python

Can not explain output of simple string operation in C
This line s = &s[n+1]; is causing your pointer to point off into the middle of nowhere. After that you start reading random garbage from it. Apparently that random garbage includes some % characters.

Categories : C

JSON-simple ClassCastException from String to JSONObject
You have json content embedded within json content. the "outer" object has a key "message" with a single string value. that string value happens to be serialized json, but the json parser isn't going to handle that for you automatically. you will have to get the message value and parse that a second time. (actually, it's worse than that, you have at least 2 levels of embedded json content).

Categories : Java

Regex issue with replace simple string
You must escape the brackets (at least the opening one). Change "[twist]" to "\[twist\]" or, using a verbatim literal to avoid the double , @"[twist]" [twist] is interpreted as any of the t, w, i, s or t character and any of them is replaced by the hello string.

Categories : C#

Simple htaccess redirect without query string
Finally I have resolved this issue, the code is as below RedirectMatch 301 ^/full-tang-polished-samurai-katana-sword.html$ http://www.example.com/final-fantasy-advent-children-cloud-buster-sword.html RewriteCond %{QUERY_STRING} ^full-tang-polished-samurai-katana-sword.html$ RewriteRule ^(.*)$ http://www.example.com/final-fantasy-advent-children-cloud-buster-sword.html? [R=301,L]

Categories : Htaccess

Finding a simple pattern in a string unless escaped
You need a negative lookbehind here: (?<!\)*[^*]+(?<!\)* In a Java string, this gives (backslash galore): "(?<!\\)\*[^*]+(?<!\\)\*" Note: the star (*) has no special meaning within a character class, therefore there is no need to escape it Note 2: (?<!...) is a negative lookbehind; it is an anchor, which means it finds a position but consumes no text. Literally, it can be translated as: "find a position where there is no preceding text matching regex ...". Other anchors are: ^: find a position where there is no available input before (ie, can only match at the beginning of the input); $: find a position where there is no available input after (ie, can only match at the end of the input); (?=...): find a position where the following text matches regex ... (this is ca

Categories : Java

Simple string concatenation in rails in view page
For example : In controller Code : def show @firstname = 'Test' @lastname = 'User' end In view page : Full Name : <%= "#{@firstname} #{lastname}" %> For further details Click Here Scenarios:- If you want to keep two variables on View page and add concatenation for those then use of space is necessary. View page: <% var string_1 = "With" var string_2 = "Rails" var addition_1 = string_1 + string_2; var addition_2 = string_1 + " " + string_2 %> <h1> First Addition -> #{addition_1} </h1> <h1> Second Addition -> #{addition_2} </h1> Output : First Addition -> WithRails Second Addition -> With Rails

Categories : Ruby On Rails

How do I query for a string in MongoDB's Simple REST interface?
As far i as know, you can't specify the type of value. This seems like a bug or limitations. If the requested value starts with a digit, it will be interpreted as a number, not as a string. As example: "abc" -> "abc", "1abc" -> 1, "123" - 123. UPDATE: I looked up the source, mongodb-src-r2.4.4srcmongodb estapi.cpp: BSONElement e = i.next(); string name = e.fieldName(); if ( ! name.find( "filter_" ) == 0 ) continue; string field = name.substr(7); const char * val = e.valuestr(); char * temp; // TODO: this is how i guess if something is a number. pretty lame right now double number = strtod( val , &temp ); if ( temp != val ) queryBuilder.append( field , number ); else queryBuilder.append( field , val ); } Look at the TODO comment and strtod function - this is t

Categories : Mongodb

How to convert a string containing a timestamp to a simple Date in MySql
The correct format is %c/%e/%Y: UPDATE members SET Time2 = STR_TO_DATE(Time, '%c/%e/%Y') where %c is the month, numeric, without leading zeros %e is the day of the month, numeric, probably without leading zeros %Y is the year Here you can find a reference of the format string

Categories : Mysql

Simple Perl string match with a special character i.e '
Your hash doesn't have a "Veteran's Affairs" key, it has a "Veteran's Affairs" value. If you defined your hash in the more common fashion: my %cot_descn = ( "Correctional" => "Veteran's Affairs", "State Pharmacy Assistance Program" => "VA Medical Center", "VA Mail Order Pharmacy" => "PHS 340B Entity" ); then the structure would be clearer. Since there is no "Veteran's Affairs" key, of course this test will send you into the else branch: if (exists $cot_descn{$var_cot_descn}) when $var_cot_descn is "Veteran's Affairs". Perhaps you have the first key/value in your %cot_descn backwards.

Categories : Perl

Simple way to make group of aplhabet and numbers from a given string
I would just use a Matcher: String str = "15D12A3C11B12A"; Matcher m = Pattern.compile("\d+\D").matcher(str); while (m.find()) System.out.println(m.group()); 15D 12A 3C 11B 12A

Categories : Java

antlr grammar for tree construction from simple logic string
This rule will disallow expressions containing both AND and OR without parentheses. It will also construct the parse tree you described by making the first AND or OR token the root of the AST, and then hiding the rest of the AND or OR tokens from the same expression. exp : atom ( 'AND'^ atom ('AND'! atom)* | 'OR'^ atom ('OR'! atom)* )? ; Edit: The second problem is unrelated to this. If you don't instruct ANTLR to consume all input by including an explicit EOF symbol in one of your parser rules, then it is allowed to consume only a portion of the input in an attempt to successfully match something. The original parse rule says "match some input as exp". The following modification to the parse rule says "match the entire input as exp". public parse : exp EOF -> ^(ROO

Categories : C#

my code regarding the simple String display is not showing the required output?
The method coolMethod() just returns the String. But looks like you forgot to put the code to print the string. You may do like this System.out.println(z.coolMethod());

Categories : Java

MvcHtmlString and HtmlString seem pretty useless wrappers around a simple string?
Their main purpose is to implement the IHtmlString marker interface which was introduced in ASP.NET 4.0. This is part of the Auto-Encoding feature of ASP.NET 4.0+. Before ASP.NET 4.0 we had only this syntax available: <%= … %> And this was simply injecting the string into the generated HTML. In 4.0 following syntax has been added: <%: … %> Which is a syntax we all should be using now. The difference with old syntax is that the string will be HTML encoded by the framework. But there are some cases when we don't want to encode the string as it is already a properly encoded HTML (for example it is an output from HtmlHelper). In such cases we should return a class which implements IHtmlString. The new syntax will be happy to accept this instead of string and will not tr

Categories : C#

How do I pass a JSON object as well as a simple string to a controller via an AJAX call?
One quick approach would be to just add it to the URL as a query string parameter: url: "http://localhost/x/api/awards/directors?operation=I" or, if you have a variable for it: url: "http://localhost/x/api/awards/directors?operation=" + operationValue Another option would be to add the "operation" value to the JSON object itself. I don't know what a Director is in your code, but for the sake of argument let's say it's this: { "ID" : 1, "Name" : "John" } Then you could add another value to that JSON object: { "ID" : 1, "Name" : "John", "operation" : "I" } This won't confuse the model binding for the server-side action method parameters. The JSON object doesn't need to exactly line up with one of the models. The model binding is going to make a best effort

Categories : Ajax

Jquery Ajax call and simple PHP json string echo server
You should use the dataType option instead of contentType if you need the response to be JSON parsed automatically by jQuery. $.ajax({ url: 'http://localhost/json/index.php', type: 'GET', dataType:'json', /* dataType instead of contentType */ ... success:function(dataF){ console.log('SuccessMsg:'+dataF); alert(dataF.surveyId); }, ... });

Categories : PHP

How to implement simple string pattern-matching using standard libraries (including boost)
VC++2008 includes TR1 regexps as a feature pack: http://www.codeproject.com/Articles/26285/Quick-Start-for-C-TR1-Regular-Expressions. Re-inventing the wheel is probably not worth it.

Categories : C++

Simple jquery find and show based on string search - cannot make it work
I would do something like this to fix your find and unhide function: function find_and_unhide (keyword,container) { $(container).find('[data-filter-value="' + keyword + '"]').show(); } I definitely think searching on the data attribute would be both faster and be more extensible in the long term, however, especially since you narrow down the DOM that needs to be searched I imagine the performance difference will be negligible either way. I personally think its cleaner to use the data attribute. Don't know much about fuzzy matching, but maybe this question will give you a starting point : Getting the closest string match

Categories : Javascript

Simple form format a time field to show '21:30' instead of entire UTC time string
You can add attr_accessor to your model (for example formatted_time) and use this field for get fromatted time and set it. Before save you can parse value of @formatted_time and apply it to time_of_event field.

Categories : Ruby On Rails

Simple form / simple fields for, limit which records are displayed
I'm not sure what exactly do you mean... But if you are wish to limit the number of records that are being pulled from the database all you need to do in the controller is to use the :limit option in find for example MyModel.find(:all, :limit => 10)

Categories : Ruby On Rails



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.