0

Using Fiddler I can see that the request is not even being made but I can't see why.

Here's the form:

@using (Html.BeginForm("Index", "FileSystemChannelIndex", FormMethod.Post, new {
channelId = @Model.ChannelId }))
{
    @Html.HiddenFor(model => model.Id)
    @Html.HiddenFor(model => model.ChannelId)
    <div class="editor-label">
        Select File Source
    </div>
    <div class="editor-field">
        @Html.DropDownListFor(
            model => model.SelectedFileSourceValue,
            new SelectList(Model.AvailableFilesSources, "Id", "Name"),
            new { id = "selectFileSource" })
    </div>
    <p>
        <input class="t-button" type="submit" value="Save" />
    </p>
}

The View originally came from:

public ViewResult Create(int channelId)
{   
    var channel = this.fullUOW.GetFileSystemChannelRepository().All.Where(c => c.Id == channelId);
    var vm = new FileSystemChannelIndexViewModel(channelId, new FileSystemChannelIndex());
    return View("Edit", vm);
}

I've tried adding the "name" attribute to the but that didn't make any difference.

Any ideas?

EDIT: More info for Jim et al...

Domain:

public class FileSystemChannel
{
   public int Id {get; set; }
   public ICollection<FileSystemChannelIndex> ChannelIndexes { get; set; }
}

public class FileSystemChannelIndex
{
   public int Id { get; set; }
   public FileSystemChannel ParentChannel { get; set; }
}

Due to a 0...* association, in the UI we have to create a FileSystemChannel first then add a FileSystemChannelIndex to it. So that's why I pass in the channelId to the FileSystemChannelIndex Create View. When submitting the new FileSystemChannelIndex the following action should be called:

[HttpPost]
public ActionResult Index(int channelId, FileSystemChannelIndexViewModel vm)
{
    //TODO: get the Channel, add the Index, save to db

    return View("Index");
}
6
  • Do you have an ActionResult called Index with [HttpPost] data annotation? Commented May 25, 2012 at 10:10
  • you must be getting some errors? what are those errors? Commented May 25, 2012 at 10:14
  • @Tim Yep, though I'm not sure if the signature is correct. Commented May 25, 2012 at 10:17
  • @3nigma - there are no obvious errors, can you suggest where I should be looking? Commented May 25, 2012 at 10:20
  • 4
    May be the validations(client side) stopping the form? Commented May 25, 2012 at 10:26

3 Answers 3

3

So thanks to Mark's comment it's due to a Select failing client side validation. Using IE dev tools to inspect the element:

<select name="SelectedFileSourceValue" class="input-validation-error" id="selectFileSource" data-val-required="The SelectedFileSourceValue field is required." data-val-number="The field SelectedFileSourceValue must be a number." data-val="true">
Sign up to request clarification or add additional context in comments.

Comments

1

empo,

further to my comment above:

empo - can you post both public ActionResult Create(////) methods (i.e. HttpPost and HttpGet) into the question as this could highlight if the issue is related to ambiguous method signatures, which i suspect could well be the case as you are posting back the same signature as the HttpGet actionresult

try adding the appropriate HttpPost actionresult along the lines of:

[HttpPost]
public ActionResult Create(FileSystemChannelIndex domainModel)
{
    if (!ModelState.IsValid)
    {
        return View(PopulateEditViewModel(domainModel));
    }

    _serviceTasks.Insert(domainModel);
    _serviceTasks.SaveChanges();
    return this.RedirectToAction("Edit", new {id = domainModel.ChannelId});
}

your original HttpGet (which feels 'wierd' to me):

[HttpGet]
public ViewResult Create(int channelId) {   
    var channel = this.fullUOW.GetFileSystemChannelRepository().All
       .Where(c => c.Id == channelId);
    var vm = new FileSystemChannelIndexViewModel(channelId, 
        new FileSystemChannelIndex());
    return View("Edit", vm); 
}

and inside your Edit actionresult, you'd grab the entity based on the passed in id. might work, might not. not sure without a fuller picture of your domain and logic.

obviously, your own plumbing will vary, but this should give an idea of what should be expected.

3 Comments

Jim, see my edit above. I didn't think it was due to the controller though because the page is not even making a request.
Jim there is no [HttpPost] Create because I want to return to the Index view, as you can see in the Html.BeginForm parameters. I'm starting to think I got this all wrong and should have a Create action which is called but return the Index view
empo- i think you've possibly got it wrong if using index as a httppost action. the standard practice is to have a 'pair' of actions, one that GETs to required objects and values for the post, the other that accepts the POSTed values and then does a redirect (PRG).
0

How can you have Model.Id when you are creating something? Maybe Model.Id is null and because you cannot post

4 Comments

it's the same view for create and edit. if id = 0 then create if id > 0 then edit
why do you need this? new { channelId = @Model.ChannelId }
channelId Hidden field will be posted
I was trying different things to work out why the action wasn't being called and didn't remove it from my sample code.

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.