hidden fields in migrating recaptcha to v2 - c#

The original code
#Html.Hidden("hf-register-publickey", SettingsHelper.CaptaPublicKey, new { id = "hf-register-publickey" })
<div class="editor-field">
<script src="#string.Format("{0}/recaptcha/api/challenge?k={1}", SettingsHelper.CaptaHost, SettingsHelper.CaptaPublicKey)" type="text/javascript"></script>
<div id="captcha_contain"></div>
<noscript>
<iframe src="#string.Format("{0}/recaptcha/api/noscript?k={1}", SettingsHelper.CaptaHost, SettingsHelper.CaptaPublicKey)"
height="300" width="500" frameborder="0"></iframe>
<br />
<textarea id="recaptcha_challenge_field" name="recaptcha_challenge_field" rows="3" cols="40">
</textarea>
<input type="hidden" id="recaptcha_response_field" name="recaptcha_response_field" value="manual_challenge"></input>
</noscript>
</div>
My question is on the first line. Do I still need the hidden fields with v2? I can't find any docs that address this.

Related

ASP.NET Core HTML Helper is not setting Default Value for Date

I have a form where I want the date to default to today's date.
<div class="form-group">
<label asp-for="ThrDate" class="control-label"></label>
<input asp-for="ThrDate" class="form-control" value="#DateTime.Now"
type="date" asp-format="{0:yyyy-MM-dd HH:mm}" />
<span asp-validation-for="ThrDate" class="text-danger"></span>
</div>
My research would suggest that this would work, but the value is not actually passing through. Oh, and I still want the date picker to work.
Thanks!
You can try the following code:
<div class="form-group">
<label asp-for="ThrDate" class="control-label"></label>
<input asp-for="ThrDate" class="form-control" id="date_info" type="date" asp-format="{0:yyyy-MM-dd}" />
<span asp-validation-for="ThrDate" class="text-danger"></span>
</div>
#section Scripts{
<script>
$(document).ready(function () {
var time = new Date();
var day = ("0" + time.getDate()).slice(-2);
var month = ("0" + (time.getMonth() + 1)).slice(-2);
var today = time.getFullYear() + "-" + (month) + "-" + (day);
$('#date_info').val(today);
})
</script>
}
Result:
And if you want use datetimepicker,you can use following code:
<div class="form-group">
<label asp-for="ThrDate" class="control-label"></label>
<div class="input-group date" id="datetimepicker1" data-target-input="nearest">
<input class="form-control datetimepicker-input" asp-for="ThrDate" type="text" data-target="#datetimepicker1" />
<div class="input-group-append" data-target="#datetimepicker1" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
</div>
</div>
#section Scripts{
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/tempusdominus-bootstrap-4/5.0.1/js/tempusdominus-bootstrap-4.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tempusdominus-bootstrap-4/5.0.1/css/tempusdominus-bootstrap-4.min.css" />
<script>
$('#datetimepicker1').datetimepicker({
format: 'DD/MM/YYYY HH:mm',
defaultDate: new Date(),
});
</script>
}
Result:
And another post gives us the answer:
Set default input value Datetime.Now on create view MVC ASP.NET Core 2?
but it's in the comments, so I will detail here.
In the controller, in the GET, set the value of the model item, such like:
PostThr postThr = new PostThr { ThrDate = DateTime.Now };
return view(model);
once you do this, the value assigned in the controller passes to the view. No modification to the view is necessary.
Side note: I seem to now have trouble with the formatting of the value, but that's rich world problems, or another question.
Shout out to Stephen Muecke!

"The element is missing the tag name following the namespace" Warning

I have an asp.net webform that works excellent,but the visual studio detects a warning says that "The element is missing the tag name following the namespace".
It is about tag helper that i use wrong.I have added my code snippet below.
How can i fix that problem?
Thanks in advance.
My Code Snippet :
<body>
<asp: #using (Html.BeginForm("LoginControl", "Home", FormMethod.Post, new { #class = "form-horizontal", role = "form" })) />
<% { %>
<div class="container">
<div class="row" >
<div class="col-sm-6 col-md-4 col-md-offset-4" >
<div class="account-wall" style="background-color:darkgrey">
<img class="profile-img" src="images/Logo.png"
alt=""/>
<form class="form-signin" runat="server">
<input type="text" runat="server" class="form-control" id="UserName" placeholder="Kullanıcı Adı" required="required" autofocus="autofocus" />
<input type="password" runat="server" class="form-control" id="Password" placeholder="Şifre" required="required" />
<asp:button runat="server" ID="btnGiris" class="btn btn-lg btn-primary btn-block" type="submit" Text="Giriş Yap" OnClick="Unnamed1_Click"/>
<label>
<!-- <input type="checkbox" value="remember-me">
Remember me -->
</label>
<span class="clearfix"></span>
</form>
</div>
</div>
</div>
</div>
<% } %>
</body>

Trying to implement bootstrap datepicker to my ASP.NET MVC website

I have the following calls in my View that should let me open the Calendar and select a date, I'm not sure I understand how to implement Datepicker.
<script>
$(document).ready(function () {
$(".datepicker").datepicker();
});
</script>
<li class="input-group-addon">
<label><%= CRAWebSiteMVC.Properties.Resources.EndDate %> :</label>
<input type="text" class="datepicker" placeholder="Click me!">
</li>
I have installed bootstrap datepicker on the NuGet, what am I missing or not understanding?
Use this for initizalis your Datepicker:
<script type="text/javascript">
$(function () {
$('#date').datepicker({
format: 'dd.mm.yyyy',
weekStart: 1,
clearBtn: true,
language: 'de-DE',
autoclose: true,
forceParse: false,
calendarWeeks: true
});
});
</script>
<li class="input-group-addon">
<label><%= CRAWebSiteMVC.Properties.Resources.EndDate %> :</label>
<input id="date" type="text" class="datepicker" placeholder="Click me!">
</li>
For more formatting see bootstrap-datepicker sandbox you will also find an example of the implementation
this is how you implement bootstrap datepicker in html page link
<div class="container">
<div class="row">
<div class='col-sm-6'>
<div class="form-group">
<div class='input-group date' id='datetimepicker1'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<script type="text/javascript">
$(function () {
$('#datetimepicker1').datetimepicker();
});
</script>
</div>
</div>
how to test if bootstrap 3 is loaded or not link
// Will be true if bootstrap 3 is loaded, false if bootstrap 2 or no bootstrap
var bootstrap3_enabled = (typeof $().emulateTransitionEnd == 'function');

Mail sending using Razor form

I have a form in my razor cshtml file. I need to send a mail on button click. How can we write the code in the same razor file?
For now my code checks the IsPost property and shows a javascript alert if true, but the alert is not showing. How can we get the values by clicking the submit button?
#inherits RazorFunction
#using System;
#{
if (IsPost)
{
<script>
alert('aaaa');
</script>
}
}
#{
<form method="post">
<div class="form_main">
<div class="col-md-6">
<input type="text" id="txtName" name="yourname" placeholder="الإسم" />
</div>
<div class="col-md-6">
<input type="text" id="txtEmail" placeholder="لبريد الإلكتروني" />
<div class="col-md-6">
<input type="text" id="txtPhone" placeholder="رقم الهاتف" />
</div>
<div class="col-md-6">
<input type="text" id="txtSubject" placeholder="الموضوع" />
</div>
<div class="col-md-12">
<input type="text" id="txtMsg" placeholder="تعليق" textmode="MultiLine" />
</div>
<div class="col-md-12">
<input type="button" id="btnSubmit" value="Submit" class="form_main_button11" data-dismiss="modal" />
<input type="button" id="btnCancel" value="Clear" class="form_main_button11" />
</div>
</div>
</div>
</form>
}
I good option to send e-mail using Razor's view engine is MvcMailer:
Sample.cshtml view:
Hello #ViewBag.Name:<br />
Welcome to MvcMailer and enjoy your time!<br />
Action to send the e-mail:
public virtual MvcMailMessage Sample()
{
ViewBag.Name = "Test";
return Populate(x =>{
x.viewName = "Sample";
x.To.Add("test#example.com");
});
}
More details on this step-by-step guide.

MVC 3 multiple forms model passing to dictionary

I'm quite new to MVC 3 and I'm stuck on an issue. The main layout look like this:
<body>
<div id="conteiner_body">
<div id="conteiner_main">
<div id="container_top">
#{ Html.RenderPartial("Basket"); }
#{ Html.RenderPartial("MenuTop"); }
</div>
<div id="left_side_border">
<div id="left_side">
#{ Html.RenderPartial("SearchBox"); }
#{ Html.RenderAction("Index", "LeftMenu"); }
</div>
</div>
<div id="content">
#RenderBody()
</div>
#{ Html.RenderPartial("Footer"); }
</div>
</div>
</body>
I have 3 forms on the page. First is in MenuTop view:
#model Models.LogOnModel
<div id="conteiner_menu_top">
<div id="menu_top">
<div id="login">
<script src="#Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
#{
using (Html.BeginForm("LogOn", "Account"))
{
#Html.TextBoxFor(m => m.UserName)
#Html.PasswordFor(m => m.Password)
#Html.CheckBoxFor(m => m.RememberMe)
<input type="submit" value="Login" />
<input type="button" value="Registr" onclick="document.location.href = '/Account/Register'" />
}
}
</div>
</div>
</div>
The second is in SearchBox:
#using (Html.BeginForm("Search", "SearchBox"))
{
<div id="search_box">
<h2>Search</h2>
<input name="searchWord" class="text" type="text" />
Advanced
<input class="submit" type="submit" value="Search" />
</div>
and of course the form in RenderBody, which changes according to the context.
Problem is, when I post some form from RenderBody(), eg. Registration, I recieve following error:
The model item passed into the dictionary is of type
'Models.RegisterModel', but this dictionary requires a model item of
type 'Models.LogOnModel'.
I've tried to add to MenuTop and SearchBox their own dictionary:
Html.RenderPartial("MenuTop", new ViewDataDictionary(Models.LogOnModel))
Html.RenderPartial("SearchBox", new ViewDataDictionary(IEnumerable<Product>))
But in this case I get following error:
CS0119: 'Models.LogOnModel' is a 'type', which is not valid in the given context
Has anybody any idea, how to solve this? Thanks a lot.
#{Html.RenderPartial("MenuTop", new Models.LogOnModel());}
#{Html.RenderPartial("SearchBox", Enumerable.Empty<Product>());}

Categories

Resources