2

I have an editor field declared in razor partial view as

    <div class="form-group">
        @Html.LabelFor(model => model.sifra_materijala, new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.sifra_materijala)
            @Html.ValidationMessageFor(model => model.sifra_materijala)
        </div>
    </div>

View is called with "RenderPartial" from index.

This generate's html:

<input type="text" value="" name="sifra_materijala" id="sifra_materijala" 
data-val-remote-url="/NormativiMaterijala/MaterijalUPoziciji" 
data-val-remote-additionalfields="*.sifra_materijala" 
data-val-remote="'sifra_materijala' is invalid." 
data-val="true" class="text-box single-line">

I also have

    [HttpGet]
    public virtual JsonResult MaterijalUPoziciji(string sifra_materijala)
    { 
       // do some checking and return json result..
    }

and

    [Remote("MaterijalUPoziciji", "NormativiMaterijala", ErrorMessage = "Already Exists")]
    public string sifra_materijala { get; set; }

in model that need to be checked... All this just don't work for no obvious reason. I checked spelling, jquery unobtrusive scripts and everything is ok, but validation method is never called.

For things to be even more confusing, i have all this on another page working perfectly fine...

Can someone help me with this?

EDIT: Checking page in firebug show that no request is send after exiting/changing editbox with data that need to be validated...

I also have scripts included.

<script src="@Url.Content("~/Scripts/jquery-2.1.0.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"></script>
<script src="@Url.Content("~/Scripts/bootstrap.min.js")"></script>

I also added second validation, that is not remote and this one is working but remote is still dead...

[StringLength(10, MinimumLength = 5, ErrorMessage = "Sifra must be minimum 5 characters long")]
        [Remote("MaterijalUPoziciji", "NormativiMaterijala", ErrorMessage = "Already Exists")]
        public string sifra_materijala { get; set; }
2
  • Have you checked in something like fiddler (telerik.com/fiddler) to see if the request is being sent at all? Commented Mar 13, 2014 at 9:45
  • no request is sent to server... when i exit/change editbox, nothing happens... checked it with firebug... Commented Mar 13, 2014 at 9:49

2 Answers 2

3

I had a similar problem that no client side validation including Remote was working in a partial view. In my case because the jquery.validate bundle was in the containing page, while the partial was being loaded via ajax. I had to move the jquery.validate js script into the partial view:

 @Scripts.Render("~/bundles/jqueryval")
Sign up to request clarification or add additional context in comments.

Comments

0

Solved it after sleepless night of trying and error... problem was in "virtual" declaration of my controller function.. Removed that and working perfect now...

[HttpGet]
    public JsonResult MaterijalUPoziciji(string sifra_materijala)
    { 
       // do some checking and return json result..
    }

I hope this answer will help someone sometime...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.