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 8043543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:56:07+00:00 2026-06-05T04:56:07+00:00

I have a cshtml form where I am inputting a title and text, and

  • 0

I have a cshtml form where I am inputting a title and text, and what I wish to achieve is that if everything is valid, ie the data entry was successful, I display an image panel, and get the ID of the new entry so that I can use it inside the image panel.

At the moment I have the following :-

Controller :-

[HttpPost]
public ActionResult Create(Project project)
{
  var model = new CompositeImageModel(0);
  if (ModelState.IsValid)
  {
    model = new CompositeImageModel(project.ProjectID);
    ViewBag.ProjectID = project.ProjectID;
    db.Projects.Add(project);
    db.SaveChanges();

    return RedirectToAction("Index");
  }

  ViewBag.ProjectID = 0;

  return View(model);
}

CSHTML:=

<script type="text/javascript">
$(document).ready(function () {
  var imageList = $('#imageList'),
      submitButt = $('#submitButt');

  //hide the imageList initially
  imageList.hide(); //hide all but the first paragraph

  //when the user clicks on the create button, display the imageList
  submitButt.click(function () {
    imageList.fadeIn('slow');
  });
});
</script>

@using (Html.BeginForm())
{
  @Html.ValidationSummary(true)

  <fieldset>
    <legend>Project</legend>

    <div class="editor-label">
      @Html.LabelFor(model => model.projectModel.ProjectTitle)
    </div>
    <div class="editor-field">
      @Html.TextBoxFor(model => model.projectModel.ProjectTitle, new { style = "width:460px" })
      @Html.ValidationMessageFor(model => model.projectModel.ProjectTitle)
    </div>

    <div class="editor-label">
      @Html.LabelFor(model => model.projectModel.ProjectText)
    </div>
    <div class="editor-field">
      @Html.TextAreaFor(model => model.projectModel.ProjectText, new { cols = 55, @rows = 5 })
      @Html.ValidationMessageFor(model => model.projectModel.ProjectText)
    </div>

    <div id='submitButt'>
      <input type="submit" value="Create" />
    </div>
  </fieldset>
}

<div id='imageList'>
  <h2>Upload Image(s)</h2>

  @{ Html.RenderPartial("~/Views/File/ImageUpload.cshtml", new MvcCommons.Models.CompositeImageModel((int)ViewBag.ProjectID)); }

</div>
<div>
  @Html.ActionLink("Back to List", "Index")
</div>

My idea was to check for the ModelState.IsValid inside the jQuery script, and if Is.Valid, then display the imagePanel and retrieve the ProjectID inside the ViewBag.

However I am not sure how to retrieve this, and if after all its the best idea, or maybe there is a better idea out there.

Thanks for your help and time

  • 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-05T04:56:08+00:00Added an answer on June 5, 2026 at 4:56 am

    At the end I went for Unobtrusive Ajax, after seeing this excellent tutorial

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following view: @model MyModel1 @{ ViewBag.Title = Index; Layout = ~/Views/Shared/_Layout.cshtml;
I have mvc3 web app. inside that I have one Enquiry form once I
I have one contact form, that send the email to one of Address selected
Let's say I have a ColorsController and a Colors/Index.cshtml View for that controller. I
I'm wondering. If I have a form that is broken up into steps where
I have Results page that contains an signup form. I'm trying to use client-side
I have a simple Wall.cshtml view that loads a _Search.cshtml Partial View that looks
I am attempting to display a form that allows a user to input a
I currently have a view, manage, that lists data items. Instead of running edit
I have a cshtml page that shows notes taken from a database in a

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.