asp.net core binder doesn't work if object have more than 20 properties 0_o - asp.net-core

I have .cshtml page , it has model List
Class Indications have 20 properties. My form
#model List<Indications>
<body>
<div>
<form asp-action="EditFlatLight" asp-controller="Home" method="post" enctype="multipart/form-data" class="container">
#for (int i=0; i<Model.Count();i++)
{
var indication = Model[i].GetType().GetProperty(ViewBag.Title).GetValue(Model[i], null).ToString();
var data = ViewBag.Title;
<div class="row">
<div class="column">
<label>#Model[i].FlatNumber</label>
</div>
<div class="column">
<input type="text" class="row" value="#indication" asp-for="#Model[i].Month" tabIndex="#i">
</div>
<div class="column">
<input type="hidden" value="#ViewBag.Title" asp-for="#Model[i].Type"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].Id" asp-for="#Model[i].Id"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].Login" asp-for="#Model[i].Login"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].City" asp-for="#Model[i].City"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].Street" asp-for="#Model[i].Street"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].HouseNumber" asp-for="#Model[i].HouseNumber"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].January" asp-for="#Model[i].January"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].February" asp-for="#Model[i].February"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].March" asp-for="#Model[i].March"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].April" asp-for="#Model[i].April"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].May" asp-for="#Model[i].May"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].June" asp-for="#Model[i].June"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].July" asp-for="#Model[i].July"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].August" asp-for="#Model[i].August"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].September" asp-for="#Model[i].September"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].October" asp-for="#Model[i].October"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].November" asp-for="#Model[i].November"/>
</div>
<div class="column">
<input type="hidden" value="#Model[i].December" asp-for="#Model[i].December"/>
</div>
</div>
}
<button id="btnSave" class="btn btn-success" style="margin-right:5px">Save</button>
</form>
</div>
</body>
And if i try to pass data to controller with all parameters it return null, but if try to pass least than 20 parameters, i receive full list, please, help....
Controller code:
[HttpPost]
public async Task<IActionResult> Edit(IEnumerable<Indications> newData)
{
}
I fight with this problem whole week. I really don't understand why i get null with more than 20 properties 0_0

Related

How to pass data in Kotlin Ktor Routing without saving the data?

Is it possible to pass various data in the Routing.kt class between different routes without saving the data in a database?
I'm calling a rest api in a search ui "search.ftl" and want to show the response data in another ui "found.ftl" and they're in different fields. If the data looks good the user can click "save" and then the data really go into the database.
At the end of get("field") I need to pass the data to get("found).
That's my code so far:
Routing.kt:
route("search") {
get {
call.respond(FreeMarkerContent("search.ftl", model = null))
}
get("field") {
// API-Call and json data in response
val title = volumeInfoObject?.get("title")
val author = authors?.get(0)
val publisher = volumeInfoObject?.get("publisher")
val pageCount = volumeInfoObject?.get("pageCount")
client.close()
call.respondRedirect("/search/found")
// How to pass data to get("found")?
}
get("found") {
call.respond(FreeMarkerContent("found.ftl", model = null))
}
}
Search.ftl:
<#import "_layout.ftl" as layout />
<#layout.header>
<div>
<div class="text-center">
<h1 class="display-4">Search</h1>
</div>
<!-- // style="border:1px solid red; -->
<div class="container">
<div class="row">
<div class="form-group has-search">
<span class="fa fa-search form-control-feedback"></span>
<form action="/search/field" method="get">
<input type="text" class="form-control" name="isbn">
</form>
</div>
</div>
<br><br><br>
<div class="row">
<div class="col-sm-3">
<div class="img"><img src="/static/500x900.png" class="img-fluid" alt="Responsive image"></div>
</div>
<div class="col-sm-9">
<div class="row">
<div class="col-8 col-sm-6">
</div>
<div class="col-4 col-sm-6">
<form>
<fieldset disabled>
<legend>Book Information</legend>
<div class="mb-3">
<label for="disabledTextInput" class="form-label">Titel</label>
<input type="text" id="disabledTextInput" class="form-control" placeholder="Disabled input">
</div>
<div class="mb-3">
<label for="disabledTextInput" class="form-label">Author</label>
<input type="text" id="disabledTextInput" class="form-control" placeholder="Disabled input">
</div>
<div class="mb-3">
<label for="disabledTextInput" class="form-label">Publisher</label>
<input type="text" id="disabledTextInput" class="form-control" placeholder="Disabled input">
</div>
<div class="mb-3">
<label for="disabledTextInput" class="form-label">Pages</label>
<input type="text" id="disabledTextInput" class="form-control" placeholder="Disabled input">
</div>
<button type="submit" class="btn btn-primary">Save</button>
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</#layout.header>
Found.ftl:
<#-- #ftlvariable name="book" type="com.nw.models.Book" -->
<#import "_layout.ftl" as layout />
<#layout.header>
<div>
<div class="text-center">
<h1 class="display-4">Search</h1>
</div>
<!-- // style="border:1px solid red; -->
<div class="container">
<div class="row">
<div class="col-sm-3">
<div class="img"><img src="/static/500x900.png" class="img-fluid" alt="Responsive image"></div>
</div>
<div class="col-sm-9">
<div class="row">
<div class="col-8 col-sm-6">
</div>
<div class="col-4 col-sm-6">
<form action="/search/found" >
<legend>Book Information</legend>
<div class="mb-3">
<label for="disabledTextInput" class="form-label">Titel</label>
<input type="text" id="disabledTextInput" class="form-control" name="title" value="title">
</div>
<div class="mb-3">
<label for="disabledTextInput" class="form-label">Author</label>
<input type="text" id="disabledTextInput" class="form-control" placeholder="Disabled input">
</div>
<div class="mb-3">
<label for="disabledTextInput" class="form-label">Publisher</label>
<input type="text" id="disabledTextInput" class="form-control" placeholder="Disabled input">
</div>
<div class="mb-3">
<label for="disabledTextInput" class="form-label">Pages</label>
<input type="text" id="disabledTextInput" class="form-control" placeholder="Disabled input">
</div>
<button type="submit" class="btn btn-primary">Save</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</#layout.header>
The solution ist now like this:
I'm saving the found book directly to db and show it on my /found route:
call.respondRedirect("/search/found/${book?.id}")
On the /found page there is a delete button, so If you are not happy with the result you can directly delete the book.
get("found/{id}") {
val id = call.parameters.getOrFail<Int>("id").toInt()
call.respond(FreeMarkerContent("edit.ftl", mapOf("book" to bookFacade.book(id))))
}

Card Footer button

I am learning ASP.NET Core and Razor pages, I already did a project, and the simplicity is amazing.
Anyway, I am building a form in a card, And I want my order button to take all the with of the footer.
I already went to the documentation but I didn't find any reference to do this.
<div class="card">
<div class="card-header">
<div class="card-body">
<form method="post">
<div class="form-group row mt-5 mb-2">
<label class="col-sm-2 ">Pizza name</label>
<div class="col-sm-10">
<input type="text" asp-for="Pizzas.PizzaName" class="form-control" />
</div>
</div>
<div class="container text-center">
<div class="form-check form-check-inline">
<input class="form-check-input" asp-for="Pizzas.TomatoSauce" placeholder="Tomato Sauce" />Tomato Sauce
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" asp-for="Pizzas.Peperoni" placeholder="Peperoni" />Peperoni
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" asp-for="Pizzas.Cheese" placeholder="Cheese" />Cheese
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" asp-for="Pizzas.Muchroom" placeholder="Muchroom" />Muchroom
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" asp-for="Pizzas.Beef" placeholder="Beef" />Beef
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" asp-for="Pizzas.Pineaple" placeholder="Pineaple" />Pineaple
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" asp-for="Pizzas.Ham" placeholder="Ham" />Ham
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" asp-for="Pizzas.Tuna" placeholder="Tuna" />Tuna
</div>
</div>
</form>
</div>
<div class="card-footer">
<button class="btn btn-primary" type="submit">Order</button>
</div>
</div>
</div>
You can try to put form outside card-body and card-footer:
<div class="card">
<div class="card-header">
<form method="post">
<div class="card-body">
<div class="form-group row mt-5 mb-2">
<label class="col-sm-2 ">Pizza name</label>
<div class="col-sm-10">
<input type="text" asp-for="Pizzas.PizzaName" class="form-control" />
</div>
</div>
<div class="container text-center">
<div class="form-check form-check-inline">
<input class="form-check-input" asp-for="Pizzas.TomatoSauce" placeholder="Tomato Sauce" />Tomato Sauce
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" asp-for="Pizzas.Peperoni" placeholder="Peperoni" />Peperoni
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" asp-for="Pizzas.Cheese" placeholder="Cheese" />Cheese
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" asp-for="Pizzas.Muchroom" placeholder="Muchroom" />Muchroom
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" asp-for="Pizzas.Beef" placeholder="Beef" />Beef
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" asp-for="Pizzas.Pineaple" placeholder="Pineaple" />Pineaple
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" asp-for="Pizzas.Ham" placeholder="Ham" />Ham
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" asp-for="Pizzas.Tuna" placeholder="Tuna" />Tuna
</div>
</div>
</div>
<div class="card-footer">
<button class="btn btn-primary" type="submit">Order</button>
</div>
</form>
</div>

I want to have two different forms for two pages

I want to have a different forms for the identity.tpl page and registration.tpl.
But the two references on the same form page customer-form.tpl.
How can I do ?
My form is static, it works perfectly for the registration.tpl page.
custom-form.tpl :
{include file='_partials/form-errors.tpl' errors=$errors['']}
<form action="{$action}" id="customer-form" class="js-customer-form" method="post">
<section>
<div class="col-md-6 mt-15">
<div class="row">
<label for="">
Civilité <sup class="c-warning">*</sub>
</label>
<label class="ml-60 mr-20" for="">
<input name="id_gender"
type="radio"
value="1">
Monsieur
</label>
<label for="">
<input name="id_gender"
type="radio"
value="2">
Madame
</label>
</div>
<div class="row">
<div class="col-md-3 plr-0 ">
<label for="">
Nom <sup class="c-warning">*</sub>
</label>
</div>
<div class="col-md-6">
<input name="lastname" type="text" value="" required>
</div>
</div>
<div class="row">
<div class="col-md-3 plr-0 ">
<label for="">
Prénom <sup class="c-warning">*</sub>
</label>
</div>
<div class="col-md-6">
<input name="firstname" type="text" value="" required>
</div>
</div>
<div class="row obligatory">
<label for=""><sup>*</sup>Champs obligatoires</label>
</div>
</div>
<div class="col-md-6 pt-55">
<div class="row">
<div class="col-md-4 plr-0 ">
<label for="">
Adresse e-mail <sup class="c-warning">*</sub>
</label>
</div>
<div class="col-md-6">
<input name="email" type="email" value="" required>
</div>
</div>
<div class="row">
<div class="col-md-4 plr-0 ">
<label for="">
Mot de passe <sup class="c-warning">*</sub>
</label>
</div>
<div class="col-md-6">
<input
name="password"
type="password"
value=""
required >
</div>
</div>
<div class="row">
<div class="col-md-4 plr-0 ">
</div>
<div class="col-md-6 ml-10">
<label for="">
<input
name="newsletter"
type="checkbox"
value="1">
S’inscrire à la newsletter
</label>
<!-- <input class="mt-10" type="submit" value="S'INSCRIRE"> -->
</div>
</div>
<footer class="form-footer clearfix">
<input type="hidden" name="submitCreate" value="1">
{block "form_buttons"}
<button class="btn form-control-submit pull-xs-right" data-link-action="save-customer" type="submit">
S'INSCRIRE
</button>
{/block}
</footer>
</div>
</section>
</form>
identity.tpl :
{extends 'customer/page.tpl'}
{block name='page_content'}
<div class="container container-id container-perso">
<h2 class="legal">{l s='Your personal information'}</h2>
{render file='customer/_partials/customer-form.tpl' ui=$customer_form}
</div>
{/block}
identity.tpl :
{extends file='page.tpl'}
{block name='page_header_container'}{/block}
{block name='page_content_container'}
{hook h="displaySliderImg"}
<div class="container container-id container-user">
{block name='register_form_container'}
<h2 class="legal">{l s='Create an account'}</h2>
<p class="text-center mt-10">Remplissez les informations ci-dessous.</p>
<div class="row bg-grey ptb-30 plr-50 mt-90" id="registration">
<div class="col-md-12">
{$hook_create_account_top nofilter}
<section class="register-form">
{render file='customer/_partials/customer-form.tpl' ui=$register_form}
</section>
</div>
</div>
</div>
<p>{l s='Already have an account?'} {l s='Log in instead!'}</p>
{/block}
</div>
{/block}
Copy all content from customer-form.tpl to identity.tpl and registration.tpl and then make your modifications.
As advice, you should make some changes in corresponding front controller and model object too, because it has validation based on current customer-form.tpl fields. Code should be something like this:
{render file='customer/_partials/form-that-you-want.tpl' ui=$form-that-you-want}
Good luck.
In PrestaShop each page has a unique value and this value can be fetched using the following code:
$this->context->smarty->smarty->tpl_vars['page']->value['page_name']
You will get a different value from above variable on Identity and Registration page, you can pass the value of above variable through Smarty and add a condition in 'custom-form.tpl'

multi-step registration using bootstrapvalidator-prevent proceeding on error

I have a multi-step reg form with each step in a fieldset,i am using bootstrap validator for validation.I made the 'next' button in first step to toggle validation.And it works well...
The problem i have is,i have to prevent going to next step on an error.
Now, validation works on clicking 'next'in first step but immediately passes to next step.
I want to stay there until validation is success...
How to do this?
i m giving my chunk of code...i have all libraries included...
...
<fieldset id="first_step">
<h2 class="fs-title">Create your account</h2>
<div class="form-group">
<label class="col-md-3 control-label">Username</label>
<div class="col-md-9">
<input type="text" class="form-control" name="uname" />
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Password</label>
<div class="col-md-9">
<input type="password" class="form-control" name="pwd" />
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Confirm Password</label>
<div class="col-md-9">
<input type="password" class="form-control" id="cpwd" />
</div>
</div>
<input type="button" name="next" id="next" class="next action-button" value="Next" />
</fieldset>
<fieldset>
<h2 class="fs-title">Personal Details</h2>
<h3 class="fs-subtitle"></h3>
<div class="form-group">
<label class="col-md-3 control-label">*Register Number</label>
<div class="col-md-9">
<input type="text" class="form-control" id="Text1" name="reg" />
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">*Name</label>
<div class="col-md-9">
<input type="text" class="form-control" id="Text2" name="stname" />
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-offset-3 col-md-12">
</div>
</div>
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="submit" id="sub_but" name="submit" class="submit action-button" value="Submit" />
</fieldset>
<script type="text/javascript">
$(".next").click(function() {
$('#msform').data('bootstrapValidator').validate();
//prevent here????
//Script to slide first fielset
}
$(".previous").click(function() {
//Script to slide back to first fieldset
}
</script>

layout is not included in all pages in asp.net mvc4 application

I am developing an asp.net mvc4 application with Bootstrap 3 and i've _Layout.cshtml in "Shared" folder , in Views, i've two pages, "Index and "Register" and i've included Layout in both of these Views but It seems that Layout is included in only "Index and not in "Register" View. Following are my Index and Register Views
#{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2 align="center" class="bg-info">Login</h2>
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label"><strong>UserName : </strong></label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="UserName">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label"><strong>Password</strong></label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Sign in</button>
</div>
</div>
<h2 align="center" class="bg-info">SignIn With Other Services</h2>
</form>
<form class="form-horizontal" role="form" method="post" action="/Home/FacebookLogin">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">SignIn with Facebook</button>
</div>
</div>
</form>
<h2 align="center" class="bg-info">Don't Have an Account?</h2>
<form class="form-horizontal" role="form" method="post" action="/Home/Register">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Register</button>
</div>
</div>
</form>
![#{
ViewBag.Title = "Register";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2 align="center" class="bg-info">Register</h2>
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label"><strong>UserName : </strong></label>
<div class="col-sm-10">
<input type="email" class="form-control" id="uname" name="uname" placeholder="UserName">
<input type="button" class="btn btn-primary" id="check" value="Check Availability" >
<h4 class="bg-warning"></h4>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label"><strong>Password</strong></label>
<div class="col-sm-10">
<input type="password" class="form-control" id="upass" name="upass" placeholder="Password">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label"><strong>Retype Password</strong></label>
<div class="col-sm-10">
<input type="password" class="form-control" id="retype" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Register</button>
</div>
</div>
</form>]
Can you please check below answer
Section has been defined but not rendered for the layout page "~/Views/Shared/_Layout.cshtml": "head"
Also check for it