nayan chowdhury nayan chowdhury - 1 year ago 33
ASP.NET (C#) Question

cannot implicitly convert type 'void' to 'object'

I am completely new In .NET.and i am just trying to achieve data annotation validation on client side.For that i search on net and found some solution.
about client side validation.

i just follow those code =>(include js files in bundle(WEB.OPTIMIZATION)) code below---


and my view --

@using something
@model Vendor
ViewBag.Title = "Add Vendor";
ViewBag.Description = "TSMS-admin";

@section PageDescription{
<section class="content-header">

@section Scripts{
@if (ViewBag.Message != null)
<script type="text/javascript">
$(function () {
CustomMessage('Error', '@ViewBag.Message', 'Close');

<div class="row .col">
<div style="margin-top:20px" class="mainbox col-md-12 col-md-offset-0 col-sm-8 col-sm-offset-2">
@using (Html.BeginForm("Add", "Admin", FormMethod.Post, new { @class = "form-horizontal", @id = "AddVendorForm", @enctype = "multipart/form-data" }))
@Html.ValidationSummary(true, null, new { @class = "text-danger" })
@Html.HiddenFor(model => model.adding_date, new { @Value = System.DateTime.Now })

<div class="panel panel-info">
<div class="panel-heading">
<div class="panel-title">Add A New Vendor</div>
<div class="panel-body col-md-12">
<img class="center-block" style="border-radius: 3px;height: 200px;width: 200px;" id="venpic" src="~/Content/img/tsms/default/upload.png"><br><br /><br />
<label style="border-radius: 2px;" class="col-xs-12 btn btn-primary btn-load btn-lg" data-loading-text="Uploadinging Picture...">
<input autocomplete="off" required name="pic_path" id="ifile_img" accept="image/gif,image/jpeg,image/jpg" onchange="readURL(this,'#venpic')" type="file" style="display: none;">Choose Pic
@Html.ValidationMessageFor(model => model.pic_path, null, new { @class = "text-danger" })
<br /><br /><br />
@Html.TextBoxFor(model => model.heading, new { @style = "border-radius:3px;", @class = "form-control", @id = "VendorName", @placeholder = Html.DisplayNameFor(model => model.heading), @autocomplete = "on", @onkeyup = "uppercase(this)" })
@Html.ValidationMessageFor(model => model.heading, null, new { @class = "text-danger" })
<br />
@Html.TextAreaFor(mode => mode.body, new { @style = "border-radius:3px;", @class = "form-control", @id = "VendorDetails", @placeholder = Html.DisplayNameFor(model => model.body), @autocomplete = "on" })
@Html.ValidationMessageFor(model => model.body, null, new { @class = "text-danger" })
<div class="panel-footer">
<div class="panel-title">
<div class="form-actions no-color">
<input onclick="d()" type="button" id="AddVendor" value="Add" class="btn btn-success" /> | @Html.ActionLink("Back to List", "Manage")

problem is when i just wants to add
it showing me some kind of error like below...

how can i solve my problem.also the steps i am following to achieve data annotation validation on client side i it right/or i need to something else to achive this ---like

is it necessary to acieve this...
.net MVC expert please help me......

Answer Source

You don't need to set @Html.EnableUnobtrusiveJavaScript() and @Html.EnableClientValidation() in every view, just put this in your web.config:

 <add key="ClientValidationEnabled" value="true" />
 <add key="UnobtrusiveJavaScriptEnabled" value="true" />

Hope you have set annotation attributes on you model properties. Also, run below script after your form loads:

var form = $('form')//Give Id prop to your from
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download