Mvc CheckBoxListFor named argument specifications error - asp.net-mvc

Im using Mvc CheckBoxListFor extension. Argument specification seems quite right to me as it's shown on the demos but it still gives me named argument specifications must appear after all fixed arguments have been specified error. And i also want to specify id attribute.
Thanks for any help in advance.
#Html.CheckBoxListFor(model => model.Categories.PostedCategories.CategoryIds,
model => model.Categories.AvailableCategories,
entity => entity.CategoryId,
entity => entity.Name,
model => model.Categories.SelectedCategories,
position: Position.Horizontal,
x => new { #class = "actcheckbox" }) // here is the line that occurs that error.
#Html.ValidationMessage("catSelectionError")

As the error message suggests, you have a named argument which is followed by a fixed argument - position: Position.Horizontal. It would seem you need to do the following:
#Html.CheckBoxListFor(model => model.Categories.PostedCategories.CategoryIds,
model => model.Categories.AvailableCategories,
entity => entity.CategoryId,
entity => entity.Name,
model => model.Categories.SelectedCategories,
Position.Horizontal, // NB: No argument name
x => new { #class = "actcheckbox", id = "myid" }) // Add id here

Related

Breezejs clear multple keys

We have the following mapping in EF6:
HasRequired(x => x.modulemain).WithMany().HasForeignKey(t => t.moduleid);
HasOptional(t => t.modulerslt).WithMany().HasForeignKey(t => new { t.moduleid, t.trmendrs });
HasOptional(x => x.modulegoal).WithMany().HasForeignKey(t => new { t.moduleid, t.trmgcode });
HasOptional(x => x.modulefase).WithMany().HasForeignKey(t => new { t.moduleid, t.trmfcode });
Breezejs understands this mapping with the combination of the two keys. BUT there is a problem: Whenever the user 'clears (sets its value to NULL)' the modulegoal/modulefase/modulerslt sets the moduleid value to an empty string and the 'second key' as well. The problem is that the first keys is being used in multiple references. So clearing one of the references, mismatches the other (important) references. Is there any way to tell breeze to NOT clear the first key?

How to call function in model from form in zf 2?

Im using zend framework 2. I want to call a function in model from zend form.
The situation is Im having a combo box & I need to bind data from database to fill its options and value.
This is my select tag in zend form
$this->add(array(
'name' => 'ddlcountry',
'type' => 'Zend\Form\Element\Select',
'options' => array(
'label' => 'Country',
'value_options' => (here I've to call function),
),
));
For this value option I want to call a function which is in model below is my function in model:
public function fetchcountry()
{
$this->adapter = $this->getServiceLocator()->get('db');
$dbAdapterConfig = $this->adapter;
$dbAdapter = $dbAdapterConfig;
$driver = $dbAdapter->getDriver();
$connection = $driver->getConnection();
$result = $connection->execute("CALL sp_showcountry()");
$statement = $result->getResource();
$resultdata = $statement->fetchAll(\PDO::FETCH_OBJ);
return $resultdata;
}
before you write such a Question, please check at least the first 10 Questions on this Page, as your Question has been asked SEVERAL Times lately ;)
Please refer to my answer provided here:
How to get data from different model for select?
Or refer to my Blogpost, which covers your problem in detail
Zend\Form\Element\Select and Database-Values

How do I use the 'When' method in ASP.NET MVC Fluent Validation?

I am trying to develop a fluent valiation rule where if my TitleId FK property is null, then the TitleOther text field becomes mandatory. I have tried several combinations and orders of fluent expressions, all to no avail.
This is what I have so far, if someone can please help me get this one When part correct, I would be most grateful, and a little more educated.
context.RulesFor(p => p.TitleId).Required(p => p.Message("Title is required."));
context.RulesFor(p => p.TitleOther)
.Required(p => p.Message("Please provide your other title."))
.Length(0, 50, c => c.Message("Other title may not exceed 50 characters")
.When(p => context.RulesFor(p => p.TitleId). *[what here?]*
I haven't used FluentValidation much, but from what I understand from the docs you would need to do
.When(p => p.TitleId == null)
instead of .When(p => context.RulesFor(p => p.TitleId). *[what here?]*
I have used When in my project in Fluent Validation. I have used for 1 condition that is compare password as like below:
RuleFor(u => u.Password).NotEmpty().WithMessage("Please Enter Password"); // Normal checked for non empty
When(u => !string.IsNullOrEmpty(u.Password) && !string.IsNullOrEmpty(u.ComfirmPassword), () =>
{
RuleFor(u => u.ComfirmPassword).Equal(x => x.Password).WithMessage("Password does not match");
}); // For compare password
Hope it helps you.
Thanks.

using ahDoctrineEasyEmbeddedRelationsPlugin to embed i18n Translation

I'm using ahDoctrineEasyEmbeddedRelationsPlugin to add dynamic i18n translations to my object, so I wrote this in my object Form class
$this->embedRelations(array(
'Translation' => array(
'considerNewFormEmptyFields' => array('content', 'lang')
));
The result I got is only one input per record, "content".
I've tried this in the FormTranslation class, but no luck:
$this->useFields(array('content', 'lang'));
So what I did was to create a manual doctrine relation with a foreignAlias called "translations", and then:
$this->embedRelations(array(
'translations' => array(
'considerNewFormEmptyFields' => array('content', 'lang')
));
this almost worked, I get the lang field now, but only in the list of existing tranlations, not in the new translation form
Any ideas if I can archieve this? Thanks!
Hm , I always use for example for 'en' and 'uk' culture :
considerNewFormEmptyFields' => array('en','uk')

AutoMapper - MapFrom gives me the following error: expression tree cannot contain assignment operator

I've been using AutoMapper successfully for a while now. However, when I use MapFrom() in the CreateMap calls, I get the above error.
I have upgraded to version 2, and it seems the registries have been broken.
CreateMap<EmailInbound, EmailMessageModel>()
.ForMember(dest => dest.Subject, opt => opt.MapFrom(src => src.Subject = (string.IsNullOrEmpty(src.Subject) ? "No Subject" : src.Subject)));
Any ideas what has broken here?
You are trying to do an assignment in lambda expression instead of returning a value. Here's the fixed version.
CreateMap<EmailInbound, EmailMessageModel>()
.ForMember(dest => dest.Subject, opt => opt.MapFrom(src => string.IsNullOrEmpty(src.Subject)
? "No Subject"
: src.Subject));

Resources