Custom type conversion in model binding (ASP.NET MVC) -


i have form submits several string values. model has 1 custom type ("service"). application gives error while trying convert string value "service". new mvc. appreciate help!

controller (orders/create):

    // post: orders/create     [httppost]     public actionresult create([bind(include = "id,name,email,language,service,documentpath,content,deliveryurgent,cost,payment")] order order)     {         var errors = modelstate.values.selectmany(v => v.errors);         if (modelstate.isvalid)         {             // stuff              return view();         }          return view(order);     } 

model (order):

public class order {     [key]     public int id { get; set; }     public string name { get;set;}     public string email { get; set; }             public string language { get; set; }                     public string documentpath { get; set; }     public string content { get; set; }             public bool deliveryurgent { get; set; }     public float cost { get; set; }     public bool payment { get; set; }            public virtual service service { get; set; } } 

model (service):

public class service {     [key]     public int id { get; set; }     public string title { get; set; }     public double costperword { get;set;}     public int discount { get; set; }       public int minimumcost { get; set; }     public int urgentcost { get; set; }      [jsonignore]     public virtual icollection<order> orders { get; set; } } 

view (create):

@model testapp.models.order  @{     viewbag.title = "test"; }  <div class="jumbotron text-center">     <h1>testapp</h1> </div>  <div class="row" id="app">     <div class="col-md-offset-1 col-md-10">         <form class="form-horizontal">             <div class="row" style="margin-bottom:10px;">                 <div class="col-xs-8" style="margin-top:10px;">                      <transition name="slide-down" appear mode="out-in">                         <strong v-if="form.filepath.length == 0" style="padding-left: 5px; padding-bottom: 5px;">enter text:</strong>                     </transition>                 </div>                 <div class="col-xs-4 text-right">or <button type="button" v-on:click="selectdocument" href="#" class="btn btn-primary" style="padding: 5px 15px">upload file</button></div>                 <div style="display: none;">                     <input type="file" ref="file_doc" class="form-control" id="file_doc" name="file_doc" v-on:change="uploaddocument" accept=".txt,.pdf,.doc,.docx" />                 </div>             </div>             <div class="form-group" style="margin-bottom:0px;">                 <div class="alert alert-info" v-show="fileuploadprogress < 100 && fileuploadprogress > 0">                     uploading: {{fileuploadprogress}}%                 </div>                 <textarea v-if="form.filepath.length == 0" v-model="form.content" ref="txt_content" name="content" style="margin: 0 2%; width: 96%;" class="form-control full-width" autofocus="autofocus" rows="15" placeholder="enter text here..."></textarea>                 <div v-else class="full-width" style="text-align: center; padding: 50px 25px; background-color: #f3f9ec; border: 1px solid #aaa;">                     <p class="full-width" style="font-size: 2em">file uploaded!</p>                     <p>                         <button class="btn btn-sm btn-default" type="button" v-on:click="clearfile">                             <span class="glyphicon glyphicon-remove"></span>                             clear file                         </button>                     </p>                 </div>             </div>             <div class="row">                 <div class="col-xs-8" style="font-size: 2em" v-bind:class="{'not-visible': !(form.content.length || form.filecontentsample.length)}">                     <span class="text-muted">language: </span>                     <span class="text-success" v-if="isvalidlanguage && !loading">{{catalog.languages[form.language]}}</span>                     <span class="text-info" v-else-if="form.wordcount > 0 && loading">verifying...</span>                     <span class="text-danger" v-else-if="form.wordcount > 0 && !loading">not english</span>                 </div>                 <div class="col-xs-4 text-right" style="font-size: 2em">                     <span class="text-muted">words:</span>                     <span class="text-success" v-if="form.wordcount > 0">{{form.wordcount}}</span>                     <span class="text-danger" v-else>0</span>                 </div>             </div>             <br /><br />             @*<h4 class="text-center text-muted" style="margin-bottom: 13px; font-size: 1.7em;"><i>choose service:</i></h4>*@             <div class="row">                 <div class="col-xs-6">                     <button type="button" v-on:click="setservice('translation')" class="btn-service" v-bind:class="{'selected': form.service == 'translation'}" :disabled="!isvalidlanguage">                         <span class="glyphicon glyphicon-refresh"></span>                         <span>translation</span>                         <div class="sticker-orange">                             <span>${{price.translation.new}}</span>                             <span class="muted">was ${{price.translation.old}}</span>                         </div>                     </button>                 </div>                 <div class="col-xs-6">                     <button type="button" v-on:click="setservice('proofreading')" class="btn-service" v-bind:class="{'selected': form.service == 'proofreading'}" :disabled="!isvalidlanguage">                         <span class="glyphicon glyphicon-search"></span>                         <span>proofreading</span>                         <div class="sticker-orange">                             <span>${{price.proofreading.new}}</span>                             <span class="muted">was ${{price.proofreading.old}}</span>                         </div>                     </button>                 </div>             </div>             <br /><br />             <div class="bg-light-gray section-padding text-center">                 <div class="checkbox" style="margin-bottom: 15px; font-weight:bold;">                     <label>                         <input type="checkbox" value="true" v-model="form.urgent" :disabled="!isformvalid"> 2 days delivery ($10)                     </label>                 </div>                 <p class="lead">                     total: <strong>${{price.total}}</strong>                 </p>                 <button type="button" v-on:click="checkformvalid" class="btn btn-lg btn-primary" style="font-size:larger; padding: 15px 30px;" :disabled="!isformvalid">                     <span class="glyphicon glyphicon-ok-circle"></span>                     pay                 </button>             </div>             <br /><br />             <transition name="slide-down" appear mode="out-in">                 <div v-show="isformvalid && ispaynowclicked">                     <div class="form-group">                         <label for="name" class="col-sm-offset-2 col-sm-2 control-label">name:</label>                         <div class="col-sm-8">                             <input type="text" v-model="form.name" ref="txt_name" class="form-control" name="name" placeholder="your name">                             <span class="text-danger" v-if="!userinfostatus.name.valid && userinfostatus.name.dirty">please enter valid name.</span>                         </div>                     </div>                     <div class="form-group">                         <label for="email" class="col-sm-offset-2 col-sm-2 control-label">email:</label>                         <div class="col-sm-8">                             <input type="email" v-model="form.email" class="form-control" name="email" placeholder="email address">                             <span class="text-danger" v-if="!userinfostatus.email.valid && userinfostatus.email.dirty">please enter valid email address.</span>                         </div>                     </div>                     <br />                     <div class="text-center">                         <strong style="margin-bottom: 17px; font-size: 1.7em;">pay with</strong>                         <br />                         <div class="btn-group-lg">                             <button class="btn btn-lg btn-primary" type="button" v-on:click="submit('paypal')" :disabled="!isuserinfovalid">paypal</button>                             <button class="btn btn-lg btn-primary" type="button" v-on:click="submit('square')" :disabled="!isuserinfovalid">square</button>                         </div>                     </div>                 </div>             </transition>         </form>     </div> </div>  @scripts.render("~/bundles/axios") @scripts.render("~/bundles/vue") @scripts.render("~/bundles/site") 

the error:

"the parameter conversion type 'system.string' type 'testapp.models.service' failed because no type converter can convert between these types."

enter image description here


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -