Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8600403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:36:34+00:00 2026-06-12T01:36:34+00:00

I have a controller which looks like; [HttpPost] [Authorize(Roles = Admin)] public ActionResult ProjectAdd(PortfolioViewModel

  • 0

I have a controller which looks like;

[HttpPost]
[Authorize(Roles = "Admin")]
public ActionResult ProjectAdd(PortfolioViewModel model, int[] categories, HttpPostedFileBase thumbnail, HttpPostedFileBase image)
{
    model.ProjectImage = System.IO.Path.GetFileName(image.FileName);
    model.ProjectThubmnail = System.IO.Path.GetFileName(thumbnail.FileName);
    using (PortfolioManager pm = new PortfolioManager())
    {
        using (CategoryManager cm = new CategoryManager())
        {
            if (ModelState.IsValid)
            {
                bool status = pm.AddNewProject(model, categories);
            }
            ViewBag.Categories = cm.GetAllCategories();
            ViewBag.ProjectsList = pm.GetAllProjects();
        }
    }
    return View(model);
}

My View is;

@using (Html.BeginForm("projectAdd", "home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Add New Project</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.ProjectHeading)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ProjectHeading)
            @Html.ValidationMessageFor(model => model.ProjectHeading)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ProjecctUrl)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ProjecctUrl)
            @Html.ValidationMessageFor(model => model.ProjecctUrl)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ProjectLongDescription)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ProjectLongDescription)
            @Html.ValidationMessageFor(model => model.ProjectLongDescription)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.PromoFront)
        </div>
        @Html.EditorFor(model => model.PromoFront)
        @Html.ValidationMessageFor(model => model.PromoFront)

        <div class="editor-label">
            <label for="thumbnail">Thumbnail</label>
        </div>
        <div class="editor-field">
            <input type="file" name="thumbnail" id="thumbnail" /> 
        </div>
        <div class="editor-label">
            <label for="image">Image</label>
        </div>
        <div class="editor-field">
            <input type="file" name="image" id="image" /> 
        </div>
        <div class="editor-label">
            <label for="categories">Categories</label>
        </div>
        @foreach (var c in categories)
        {
            <input type="checkbox" name="categories" value="@c.CategoryId">
            @c.CategoryName
        }
        <p>
            <input type="submit" value="Create" class="submit" />
        </p>
    </fieldset>
}

When I try this code, The ModeState.IsValid property becomes false (I saw through debugging). However, when I remove ModeState.IsValid, the insertation is done successfully and everything works exactly what I want.
I need ModeState.IsValid property for validating my view.
Updated: My viewmodel is;

[Key]
public int ProjectId { get; set; }
[Required(ErrorMessage="Please enter project heading")]
public string ProjectHeading { get; set; }
[Required(ErrorMessage = "Please enter project Url")]
public string ProjecctUrl { get; set; }
[Required(ErrorMessage = "Please enter project description")]
public string ProjectLongDescription { get; set; }
public string ProjectShortDescription
{
    get
    {
        var text = ProjectLongDescription;
        if (text.Length > ApplicationConfiguration.ProjectShortDescriptionLength)
        {
            text = text.Remove(ApplicationConfiguration.ProjectShortDescriptionLength);
            text += "...";
        }
        return text;
    }
}
public bool PromoFront { get; set; }
[Required(ErrorMessage = "You must sepcify a thumbnail")]
public string ProjectThubmnail { get; set; }
[Required(ErrorMessage = "You must select an image")]
public string ProjectImage { get; set; }
public int CategoryId { get; set; }
public IEnumerable<Category> Categories { get; set; }

Updated 2: I found the error. the problem is

{System.InvalidOperationException: The parameter conversion from type 'System.String' to type 'PortfolioMVC4.Models.Category' failed because no type converter can convert between these types.
   at System.Web.Mvc.ValueProviderResult.ConvertSimpleType(CultureInfo culture, Object value, Type destinationType)
   at System.Web.Mvc.ValueProviderResult.UnwrapPossibleArrayType(CultureInfo culture, Object value, Type destinationType)
   at System.Web.Mvc.ValueProviderResult.ConvertTo(Type type, CultureInfo culture)
   at System.Web.Mvc.DefaultModelBinder.ConvertProviderResult(ModelStateDictionary modelState, String modelStateKey, ValueProviderResult valueProviderResult, Type destinationType)}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:36:35+00:00Added an answer on June 12, 2026 at 1:36 am

    When in debug, check the ModelState for errors. It’s a key/value dictionary with all the properties required to make the model valid. If you check the Values-property you can find the value with the Errors-list that is not empty and see what the error is.

    Example of ModelState errors

    Or add this line of code in the action method to get all the errors for the model:

    var errors = ModelState.Where(v => v.Value.Errors.Any());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a controller, Hardware which has a Create action. The model looks like:
This is the code that I have in my controller: [HttpPost] public ActionResult UpdateArticle(Article
I have a method in my Controller which looks like this: @RequestMapping(value = /test,
I have a controller action which looks like so - def upvote @post =
Well i have a complex form view model like this : public class TransactionFormViewModel
I have a view model which is just public class Visits { public List<Visit>
I have an HTML Data which looks like: <div id=foo><a class=someClass href=http://somelink>Some Title</a></div> <div
I have a DataTable which looks like below: TOTAL_CODE COD_NAME AP0001 School AP0002 Hospital
Let's assume that we have a controller with some action which could look like:
I have a dropdownlist that looks like this: @Html.DropDownListFor( x => x.Attribute.AttributeID, new SelectList(Model.Attributes,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.